帮助C程序 [英] Help with a C program
问题描述
嗨
我正在努力教自己如何用C语言编程。我是一名医生
希望能够帮助重组我的办公室。无论如何,我希望
我所拥有的这个问题很简单,对于那些更有经验的人来说,编程时可以获得
。我正在尝试使用数组的概念来计算我的后台工作人员的小时数,但是我得到了一个荒谬的错误行数。如果有人有时间帮助我,那将是非常好的。我正在使用免费的devc ++编译器。
提前感谢任何提供一些建议的人。
SK
//稍后要添加的规格
// C库
#include< stdio.h>
#include< math.h>
#include< string.h>
//全局常量
#define FULLNAME [20]
#define员工[1000]
/ *定义结构。* /
struct EMP_WeeklyPay
{
char first_name [FULLNAME];
char last_name [FULLNAME];
float RegHr;
浮动工资;
浮动OTHr;
浮动OTHrPay;
浮动GrossPay;
}
/ *重命名结构语法。 * /
typedef EMP_WeeklyPay EWP;
/ *创建一个结构数组。* /
EWP emp [EMPLOYEES];
/ *计数器* /
int n,numemp;
int count = 0;
/ *输入中的字符串* /
char部门[20 ],fn [FULLNAME],ln [FULLNAME],再次为char;
/ *临时浮动* /
浮动工资,浮动OTwage,浮动小时,浮动RegHr,
浮动OTHrPay,浮动OTHr,浮动GrossPay;
printf(\ n\\\
Mountain Pacific Corporation \ n);
printf(部门薪资计划\ n \\ nnn);
printf(请输入部门名称:);
scanf("%s",department);
/ *循环读取员工工资数据* /
for(n = 0; n<雇员; ++ n){
printf(&\\;输入员工#%d:",count_EMP);
scanf("%s%) s",& Fname,& Lname);
printf(&\\; \ n请输入员工的小时工资:
") ;
scanf("%f"& wage);
printf(\ n请输入此工作小时数
"周:");
scanf("%f",& hours);
printf( 谢谢你。处理另一名员工?;
scanf("%s",&再次);
}
/ *读入输入* /
numemp = scanf("%11s%11s%f%f%f%f%f",fn,ln& ; RegHr,
& wage,& OTHr,& OTHrPay,& GrossPay);
/ *检查用户是否完成* /
printf(\谢谢你。处理另一名员工?);
scanf("%s",再次);
while(再次==''Y''||再次==''y'');
if(再次!=''Y''&&再次!=''y'');
printf(处理结束\ nn \ n \\ nnn);
/ *处理输入* /
if(num == 7)
{
if(RegHr> 40)
{
OTHr =小时 - 40;
OTHrPay = OT * OTHr *工资;
RegHrPay = 40.0 *工资;
}
其他
{
RegHrPay =小时*工资;
OTHrPay = 0.0;
}
GrossPay = RegHrPay + OTHrPay;
strncpy( employee [n] .first_name,fn,FULLNAME-1);
employee [n] .first_name [FULLNAME-1] =''\ 0'';
strncpy(employee [n] .last_name,ln,FULLNAME-1);
employee [n] .last_name [FULLNAME-1] =''\ 0'';
员工[n] .regularhours = RegHr;
员工[n] .wage =工资;
员工[n] .overtimehours = OTHr;
员工[n] .overtimepay = OTHrPay;
员工[n] .GrossPay。 = GrossPay;
++计数;
}
/ *打印表* /
printf(\ n\\\
Mountain Pacific Corporation \ n);
printf(部门薪资计划\ n \\ nnn);
printf(" Employee Reg Hrs"
printf( -----------------------------------------"
------------------------- \ n\ n;);
>
for(n = 0; n< count; ++ n){
printf("% - 35s%-17s%12f%10f%12f%10f %% 5f" ;,
员工[n] .first_name,
员工[n] .last_name,员工[n] .RegHr,
员工[n ] .wage,employee [n] .OTHr,employee [n] .OTHrPay,
employee [n] .GrossPay);
}
}
Hi
I am trying to teach myself how to program in C. I am a physician
hoping to be able to help restructure my office. Anyhow, I amhoping
that the porblem I am having is simple to those much more experienced
in programming. I am trying to use the concept of arrays to calculate
the hours of my backoffice staff, however I am getting a ridiculous
amount of error lines. If any one has time to help me that would be
great. I am using the free devc++ compiler.
Thanks in advance to anyone who offers some advice.
SK
//Specs to be added later
//C Libraries
#include <stdio.h>
#include <math.h>
#include <string.h>
//Global Constants
# define FULLNAME[20]
# define EMPLOYEES[1000]
/*Define the structure.*/
struct EMP_WeeklyPay
{
char first_name[FULLNAME];
char last_name[FULLNAME];
float RegHr;
float wage;
float OTHr;
float OTHrPay;
float GrossPay;
}
/*Rename the structure syntax.*/
typedef EMP_WeeklyPay EWP;
/*Create an array of structures.*/
EWP emp[EMPLOYEES];
/*Counters*/
int n, numemp;
int count = 0;
/*Strings in input*/
char department[20], fn[FULLNAME], ln[FULLNAME], char again;
/*temporary float*/
float wage, float OTwage, float hours, float RegHr,
float OTHrPay, float OTHr, float GrossPay;
printf("\n\nMountain Pacific Corporation\n");
printf("Department Salary Program\n\n");
printf("Please enter the name of the department: ");
scanf("%s", department);
/*Loop to read in employee wage data*/
for (n = 0; n < EMPLOYEES; ++n){
printf("\nEnter employee # %d: ", count_EMP);
scanf("%s %s", &Fname, &Lname);
printf("\nPlease enter the hourly wage for the employee:
");
scanf("%f", &wage);
printf("\nPlease enter the number of hours worked this"
" week: ");
scanf("%f", &hours);
printf("\nThank you. Process another employee?");
scanf("%s", &again);
}
/*Read in the input*/
numemp = scanf("%11s%11s%f%f%f%f%f", fn, ln, &RegHr,
&wage, &OTHr, &OTHrPay, &GrossPay);
/*Check if user is done*/
printf("\nThank you. Process another employee?");
scanf("%s", &again);
while(again == ''Y'' || again == ''y'');
if(again != ''Y'' && again !=''y'');
printf("End of processing\n\n\n");
/*Process the input*/
if(num == 7)
{
if (RegHr > 40)
{
OTHr = hours - 40;
OTHrPay = OT * OTHr * wage;
RegHrPay = 40.0 * wage;
}
else
{
RegHrPay = hours * wage;
OTHrPay = 0.0;
}
GrossPay = RegHrPay + OTHrPay;
strncpy(employee[n].first_name, fn, FULLNAME-1);
employee[n].first_name[FULLNAME-1] = ''\0'';
strncpy(employee[n].last_name, ln, FULLNAME-1);
employee[n].last_name[FULLNAME-1] = ''\0'';
employee[n].regularhours = RegHr;
employee[n].wage = wage;
employee[n].overtimehours = OTHr;
employee[n].overtimepay = OTHrPay;
employee[n].GrossPay. = GrossPay;
++count;
}
/*Print Table*/
printf("\n\nMountain Pacific Corporation\n");
printf("Department Salary Program\n\n");
printf("Employee Reg Hrs "
"Overtime Hrs Gross\n");
printf("-----------------------------------------"
"-------------------------\n\n");
for(n=0; n < count; ++n) {
printf("%-35s%-17s%12f%10f%12f%10f%%5f",
employee[n].first_name,
employee[n].last_name, employee[n].RegHr,
employee[n].wage, employee[n].OTHr, employee[n].OTHrPay,
employee[n].GrossPay);
}
}
推荐答案
2005年11月13日00:29:53 -0800,SK < BA ****** @ aol.com>写在
comp.lang.c:
On 13 Nov 2005 00:29:53 -0800, "SK" <ba******@aol.com> wrote in
comp.lang.c:
嗨
首先要做的是礼貌。不要分别向不同的组发布相同的消息
。如果你确定它比一个团体更多的是b / b
,请交叉发布。
我正在努力教自己如何在C中编程。我是一名医生<希望能够帮助重组我的办公室。无论如何,我希望我所拥有的问题对于那些在编程方面更有经验的人来说很简单。我正在尝试使用数组的概念来计算我的后台工作人员的小时数,但是我得到了一个荒谬的错误行数。如果有人有时间帮助我,那将是非常好的。我正在使用免费的devc ++编译器。
提前感谢任何提供建议的人。
SK
//稍后要添加的规范
// C库
#include< stdio.h>
#include< math.h>
#include< string.h>
//全局常量
#define FULLNAME [20]
#define EMPLOYEES [1000]
Hi
First things first, good manners. Don''t post the same message
separately to different groups. If you are sure it belongs in more
than one group, cross-post it.
I am trying to teach myself how to program in C. I am a physician
hoping to be able to help restructure my office. Anyhow, I amhoping
that the porblem I am having is simple to those much more experienced
in programming. I am trying to use the concept of arrays to calculate
the hours of my backoffice staff, however I am getting a ridiculous
amount of error lines. If any one has time to help me that would be
great. I am using the free devc++ compiler.
Thanks in advance to anyone who offers some advice.
SK
//Specs to be added later
//C Libraries
#include <stdio.h>
#include <math.h>
#include <string.h>
//Global Constants
# define FULLNAME[20]
# define EMPLOYEES[1000]
医生,我这样做会很疼!
然后不要这样做。
请提供您的教师的电子邮件地址,我们会发给您
直接完成作业。
-
Jack Klein
主页: http://JK-Technology.Com
常见问题解答
comp.lang.c http:// www。 eskimo.com/~scs/C-faq/top.html
comp.lang.c ++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang .learn.c-c ++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
"Doctor, it hurts when I do this!"
"Then don''t do it."
Please provide your instructor''s email address and we''ll send you
completed assignment directly.
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
2005年11月13日00: 29:53 -0800,在comp.lang.c,SK
< ba ****** @ aol.com>写道:
On 13 Nov 2005 00:29:53 -0800, in comp.lang.c , "SK"
<ba******@aol.com> wrote:
//全局常量
#define FULLNAME [20]
#define EMPLOYEES [1000]
我假设您正在尝试创建一个值为20的常量FULLNAME。
#define FULLNAME 20
/ *临时浮动* /
浮动工资,浮动OTwage,浮动小时,浮动RegHr,
浮动OTHrPay,浮动OTHr,浮动GrossPay;
强烈建议您不要使用花车进行任何数学计算。在大多数情况下,它们不够准确。
scanf(%f,& wage);
强烈建议你不要使用scanf。要探究原因,请尝试输入
意外的东西,如两千,什么都没有,等等。
fgets()更安全功能。之后你可以sscanf字符串
。
printf(\ n请输入工作小时数
周:);
scanf("%f"& hours);
printf(" \ n谢谢你。处理另一名员工?");
在处理下一个员工之前,你不需要用工资和工时来做些什么吗?也许存放它们?
scanf("%s",&再次);
}
/ *读入输入* /
你没有提示用户输入任何内容 - 他不知道该怎么做?b $ b类型......
while(再次==''Y'' ||再次==''y'');
//Global Constants
# define FULLNAME[20]
# define EMPLOYEES[1000]
I assume you''re trying to create a constant FULLNAME with value 20.
#define FULLNAME 20
/*temporary float*/
float wage, float OTwage, float hours, float RegHr,
float OTHrPay, float OTHr, float GrossPay;
Strongly recommend you don''t use floats for any mathematical
calculations. They''re not accurate enough in most cases.
scanf("%f", &wage);
Strongly recommend you don''t use scanf. To explore why, try typing in
unexpected things such as "two thousand", nothing at all, etc.
fgets() is a much safer function. You can sscanf the string
afterwards.
printf("\nPlease enter the number of hours worked this"
" week: ");
scanf("%f", &hours);
printf("\nThank you. Process another employee?");
Don''t you need to do someething with wage and hours before you process
the next employee? Store them perhaps?
scanf("%s", &again);
}
/*Read in the input*/ You didn''t prompt the user for any input - he won''t know what to
type...
while(again == ''Y'' || again == ''y'');
这边做什么?应该有一个地方做什么
做{
//东西
而(条件);
$ b此时为$ b,核心倾销,错误太多,纠正错误,然后再次尝试再次......
-
Mark McIntyre
CLC常见问题< http://www.eskimo.com/~scs/C-faq/top.html>
CLC自述文件:< http://www.ungerhu.com/jxh/clc.welcome.txt>
---- ==通过Newsfeeds.Com发布 - 无限制 - 无限制 - 安全使用新闻= = ----
http://www.newsfeeds.com # 1个世界新闻组服务! 120,000多个新闻组
---- =东海岸和西海岸服务器农场 - 通过加密实现全隐私= ----
whats this while doing here? There should be a do somewhere
do {
// stuff
while(condition);
at this point, "core dumped, too many errors, correct those ones and
try again"....
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jack Klein写道:
Jack Klein wrote:
2005年11月13日00:29:53 -0800,SK < BA ****** @ aol.com>写在
comp.lang.c:
On 13 Nov 2005 00:29:53 -0800, "SK" <ba******@aol.com> wrote in
comp.lang.c:
我正在努力教自己如何用C编程。我是一名医生/>希望能够帮助重组我的办公室。
I am trying to teach myself how to program in C. I am a physician
hoping to be able to help restructure my office.
请提供您的教师的电子邮件地址,我们会发给您
已完成的作业直接。
Please provide your instructor''s email address and we''ll send you
completed assignment directly.
我想知道这项任务是否被陈述为
你是医生,希望......? br />
-
pete
I wonder if the assignment was stated as
"You are a physician, and hoping ..."?
--
pete
这篇关于帮助C程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!