嘿,大家好,我在我的学校项目程序中需要帮助,它是 switch()、if()...else、if()...else if()... 以及任何其他构造的组合您需要有正确的输出。
程序规范:
某公司加薪如下:
技术人员:工作10年以上加薪5%。其他3%
行政人员:
- 会计部门人员为 6%
- 营销部门人员为 4%
- 其他 3%
这是我的代码,但是每次我编译并运行它时都会出现运行时错误:希望有人可以帮助我,因为我是编程新手,到期日是明天
#include <stdio.h>
#include <conio.h>
int main (void)
{
int currentsalary;
int yearsinservice;
int percent;
float newsalary;
char choice1 ,choice2;
printf("Current Salary: \n");
scanf("%d", ¤tsalary);
printf("Staff Category: \n");
printf("T - technical \n");
printf("A - administrative \n");
printf("O - others \n");
printf("Enter the staff Category: \n");
scanf(" %c", choice1);
switch (choice1)
{
case't':
case'T': printf("No. of years in Service: ");
scanf("%d", &yearsinservice);
if (yearsinservice > 10)
{
percent = currentsalary*.05;
newsalary = currentsalary + percent;
printf("New Salary: %.2f", newsalary);
}
else
{
percent = currentsalary*.03;
newsalary = currentsalary + percent;
printf("New Salary: %.2F", newsalary);
}
break;
case'a':
case'A': printf("Department where the staff belongs:");
printf("A - accounting\n");
printf("M - marketing\n");
printf("O - others\n");
printf("Choose the department:\n");
scanf(" %c",&choice2);
if (choice2 == 'a' || choice2 == 'A')
{
percent = currentsalary*.06;
newsalary = currentsalary+percent;
printf("New Salary: %.2f", newsalary);
}
else if (choice2 == 'm' || choice2 == 'M');
{
percent = currentsalary*.04;
newsalary = currentsalary+percent;
printf("New Salary: %.2f", newsalary);
}
else
{
percent = currentsalary*.03;
newsalary = salary+percent;
printf("New Salary; %.2f", newsalary);
}
break;
case'o':
case'O': percent = currentsalary*.02;
newsalary = currentsalary + percent;
printf("New Salary: %.2f",newsalary);
break;
default: printf("Wrong Input");
getch();
}
getch();
return 0;
}
示例输出1中的结果应该相同:
目前工资:15000
员工类别:
T-技术
A-行政
O-其他
输入员工类别:T
没有。服务年数:11
新薪资:15750.00
输出2:
目前工资:20000
员工类别:
T-技术
A-行政
O-其他
输入员工类别:A
员工所属部门
A——会计
M——营销
O-其他
选择部门:A
新薪资:21200.00
输出3:
目前工资:15000
员工类别:
T-技术
A-行政
O-其他
输入员工类别:O
新薪资:15300.00
最佳答案
您在这行遇到问题
else if (choice2 == 'm' || choice2 == 'M');
^
删除末尾的分号;
关于c - 以下代码遇到段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29702244/