#include<stdio.h>
void main()
{
int num,incentive;
int salary=1500;
float w_hr, avg_time,LOP,tot_sal;
int tot_hr=50;
printf("Enter the no. of projects allocated\n");
scanf("%d",&num);
printf("Enter the no. of working hours\n");
scanf("%f",&w_hr);
if(num<=10)
{
if(w_hr<tot_hr)
{
avg_time=w_hr/num;
printf("Average Time Taken(Hrs)\n%f",avg_time);
}
else if(w_hr>50&&w_hr<=55)
{
LOP=0.5;
tot_sal=(((100-LOP)/100)*salary);
printf("You have exceeded the timeline\n");
printf("Your Salary is Rs.%.2f",tot_sal);
}
else if(w_hr>55&&w_hr<=60)
{
LOP=1.0;
tot_sal=(((100-LOP)/100)*salary);
printf("You have exceeded the timeline\n");
printf("You Salary is Rs.%.2f",tot_sal);
}
else if(w_hr>60&&w_hr<=70)
{
LOP=1.5;
tot_sal=(((100-LOP)/100)*salary);
printf("You have exceeded the timeline\n");
printf("Your Salary is Rs.%.2f",tot_sal);
}
else
printf("Invalid input");
}
}
else
{
printf("The maximum limit on project count has been specified as %d. SORRY!!",num);
}
while(w_hr<tot_hr)
{
if(avg_time<5)
{
incentive=5000;
tot_sal=salary+incentive;
printf("Your Salary is %.f",tot_sal);
}
else if(avg_time>=5&&avg_time<7)
{
incentive=2000;
tot_sal=salary+incentive;
printf("Your Salary is %.f",tot_sal);
}
else if(avg_time>=7&&avg_time<10)
{
incentive=1500;
tot_sal=salary+incentive;
printf("Your Salary is %.f",tot_sal);
}
else
{
incentive=500;
tot_sal=salary+incentive;
print("Your Salary is %.f",tot_sal);
}
}
}
在上述程序中,出现以下错误,
calculatesalary.c:44: error: expected identifier or ‘(’ before ‘else’
else
^
calculatesalary.c:48: error: expected identifier or ‘(’ before ‘while’
while(w_hr<tot_hr)
^
calculatesalary.c:75: error: expected identifier or ‘(’ before ‘}’ token
}
^
我在else部分和while循环中出现错误,指出在(
,}
和while
令牌之前有标识符或else
。< / p>
循环嵌套的方式有错吗?
代码的问题: -
Ragav,客户经理在Abil Solutions工作。有一天,他决定修改计算组织中处理项目的员工的薪水的方式。他必须维护员工在时间线内完成的项目的薪资细节。完成分配工作的总小时数为50.员工可以同时处理最多10个项目。员工不应超越时间表。如果员工花费的时间超过了他的工资时间,他将获得工资损失。如果他以较低的平均时间完成项目,他将获得激励。整个项目的工资是Rs.1500 / -
如果所花费的时间大于50小时,则计算工资与工资损失,无需计算平均时间。平均花费的时间必须是浮动类型。
平均时间/项目(小时)奖励(卢比)
低于5 5000
= 5且<7 2000
= 7且<10 1500
= 10 500
拍摄时间(小时)工资损失(%)
50且<= 55 0.5
55且&lt; = 60 1.0
60且&lt; = 70 1.5
70输入无效
测试用例
输入1
输入分配的项目编号
5
输入工作时数
30
输出1
平均拍摄时间(小时)
6.0
你的薪水是9500卢比
输入2
输入分配的项目编号
8
输入工作时数
55
输出2
您已超出时间表。
你的薪水是1140卢比
输入3
输入分配的项目编号
12
输入工作时数
40
输出3
项目计数的最大限制已指定为10.抱歉!!
答案 0 :(得分:0)
在第46行的else语句后面有一个额外的}
。在纠正之后,代码将是
#include <stdio.h>
int main()
{
int num,incentive;
int salary=1500;
float w_hr, avg_time,LOP,tot_sal;
int tot_hr=50;
printf("Enter the no. of projects allocated\n");
scanf("%d",&num);
printf("Enter the no. of working hours\n");
scanf("%f",&w_hr);
if(num<=10)
{
if(w_hr<tot_hr)
{
avg_time=w_hr/num;
printf("Average Time Taken(Hrs)\n%f",avg_time);
}
else if(w_hr>50&&w_hr<=55)
{
LOP=0.5;
tot_sal=(((100-LOP)/100)*salary);
printf("You have exceeded the timeline\n");
printf("Your Salary is Rs.%.2f",tot_sal);
}
else if(w_hr>55&&w_hr<=60)
{
LOP=1.0;
tot_sal=(((100-LOP)/100)*salary);
printf("You have exceeded the timeline\n");
printf("You Salary is Rs.%.2f",tot_sal);
}
else if(w_hr>60&&w_hr<=70)
{
LOP=1.5;
tot_sal=(((100-LOP)/100)*salary);
printf("You have exceeded the timeline\n");
printf("Your Salary is Rs.%.2f",tot_sal);
}
else
printf("Invalid input");
}
else
{
printf("The maximum limit on project count has been specified as %d. SORRY!!",num);
}
while(w_hr<tot_hr)
{
if(avg_time<5)
{
incentive=5000;
tot_sal=salary+incentive;
printf("Your Salary is %.f",tot_sal);
}
else if(avg_time>=5&&avg_time<7)
{
incentive=2000;
tot_sal=salary+incentive;
printf("Your Salary is %.f",tot_sal);
}
else if(avg_time>=7&&avg_time<10)
{
incentive=1500;
tot_sal=salary+incentive;
printf("Your Salary is %.f",tot_sal);
}
else
{
incentive=500;
tot_sal=salary+incentive;
printf("Your Salary is %.f",tot_sal);
}
}
return 0;
}
答案 1 :(得分:0)
while循环正在创建一个问题。我做了必要的更正:
#include <stdio.h>
int main()
{
int num,incentive;
int salary=1500;
float w_hr, avg_time,LOP,tot_sal;
int tot_hr=50;
printf("Enter the no.of projects allocated\n");
scanf("%d",&num);
printf("Enter the no.of working hours\n");
scanf("%f",&w_hr);
if(num<=10){
if(w_hr<tot_hr){
avg_time=w_hr/num;
printf("Average Time Taken (Hrs)\n%.1f",avg_time);
if(avg_time<5.0){
incentive=5000;
tot_sal=salary*num+incentive;
printf("\nYour Salary is Rs.%.f",tot_sal);
}
else if(avg_time>=5.0 && avg_time<7.0){
incentive=2000;
tot_sal=salary*num+incentive;
printf("\nYour Salary is Rs.%.f",tot_sal);
}
else if(avg_time>=7.0 && avg_time<10.0){
incentive=1500;
tot_sal=salary*num+incentive;
printf("\nYour Salary is Rs.%.f",tot_sal);
}
else{
incentive=500;
tot_sal=salary*num+incentive;
printf("\nYour Salary is Rs.%.f",tot_sal);
}
}
else if(w_hr>50&&w_hr<=55){
LOP=0.5;
tot_sal=num*(((100-LOP)/100)*salary);
printf("You have exceeded the timeline\n");
printf("\nYour Salary is Rs.%.f",tot_sal);
}
else if(w_hr>55&&w_hr<=60){
LOP=1.0;
tot_sal=(((100-LOP)/100)*salary);
printf("You have exceeded the timeline\n");
printf("\nYour Salary is Rs.%.2f",tot_sal);
}
else if(w_hr>60&&w_hr<=70){
LOP=1.5;
tot_sal=(((100-LOP)/100)*salary);
printf("You have exceeded the timeline\n");
printf("\nYour Salary is Rs.%.2f",tot_sal);
}
else
printf("\nInvalid input");
}
else{
printf("The maximum limit on project count has been specified as 10. Sorry!!");
}
return 0;
}