C为什么要赢得我的程序循环以及" if-statements"不行吗?

时间:2018-05-09 23:43:07

标签: c++ c loops if-statement while-loop

**这个问题有一个我忽略的简单拼写错误。我用" ="而不是" =="对于我的if语句。我是编码的新手,虽然我多次阅读编码,但我从未接受过编码。我向将来看这个问题的人道歉。现在,问题中的编码已更新,以便正常运行。

干杯, Cronin709 **

我正在尝试为学校编写一个代码,允许用户根据其工作的员工类型计算不同的工资。我相信我已经正确完成了所有的数学编码,但是我需要在选择每个员工后进行程序循环。这是我到目前为止完成的编码:

int paycode = 0;                                        
double manager_salary;                                  
double worker_salary;                                   
double worker_hours;                                    
double ot;                                              
double worker_wage;                                     
double sales;                                           
double commission;                                      
double pieces;                                          
double piece_wage;                                      
double pieceworker;                                     

while (paycode >= 0 && paycode != 1)                    
{
    printf("\n Enter the employee paycode (1-4) (-1 to end): ");        
    scanf_s("%d", &paycode);

    if (paycode == 1)                                                   
    {
        printf("\n Manager Selected");                                  
        printf("\n Enter weekly Salary: ");                             
        scanf_s("%lf", &manager_salary);
        printf("\nManagers Pay is $%.2f", manager_salary);              
    }
    else if (paycode == 2)
    {
        printf("\n Hourly Worker Selected");                            
        printf("\n Enter the hourly salary: ");                         
        scanf_s("%lf", &worker_salary);
        printf("\n Enter the total hours worked: ");                    
        scanf_s("%lf", &worker_hours);
        if (worker_hours > 40.00)                                               
            ot = (worker_hours - 40.00) * worker_salary *1.5;                   
        else
            ot = 0.00;                                                          
        if (worker_hours > 40.00)                                               
            worker_wage = 40 * 16.78 + ot;                                      
        else
            worker_wage = worker_hours * worker_salary;                         
        printf("\n Hourly Worker's Pay is $%.2f", worker_wage);                 
    }
    else if (paycode == 3)
    {
        printf("\n Commission Worker Selected");                        
        printf("\n Enter gross weekly sales: ");                        
        scanf_s("%lf", &sales);
        commission = sales * .057 + 250;                                
        printf("\n Commission Worker's Pay is $%.2f", commission);      
    }
    else if (paycode == 4)
    {
        printf("\n Pieceworker Selected");                              
        printf("\n Enter number of pieces: ");                          
        scanf_s("%lf", &pieces);
        printf("\n Enter wage per piece: ");                            
        scanf_s("%lf", &piece_wage);
        pieceworker = pieces * piece_wage;
        printf("\n Pieceworker's pay is $%.2f", pieceworker);           
    }
}
return 0;

}

当我运行程序时,if语句不起作用,程序只是吐出我写的每一个printf语句。

请帮我告诉我如何使我的if语句正常工作以及如何在正确填写员工薪水时正确制作循环。

TIA

2 个答案:

答案 0 :(得分:1)

你的if语句需要'=='而不是'='。如果语句将开始工作,请进行更改并进行尝试。

答案 1 :(得分:-1)

使用 == 代替 =
例如

if (paycode == 1)
{
}