我的哨兵while循环提示两次C,无法弄清楚什么是错误的

时间:2017-11-12 00:56:23

标签: c loops sentinel

我已经花了几个小时摆弄这个,我无法弄清楚为什么会一直提示两次,我已经搜索了这个网站并跟进了一些提示,比如清除缓冲区等等,当它从函数

返回时,循环仍然提示两次

请输入退出车库的人员类型

员工的S或s。 患者为P或p。 G或g为来宾

请输入退出车库的人员类型

员工的S或s。 患者为P或p。 G或g为来宾

任何建议对他有帮助。这是我的代码。

#include <stdio.h>
#define SENTINEL -99
double clientC;
double revenue;
char work;
double hours;

int main(void)
{

double hours;
printf("Type E or e when you, the parking operator are ready to clock out of         
the day.\n");
int loop = 0;

while (loop != SENTINEL)
{


    printf("Please enter the type of person exiting the garage\nS or s for 
  Staff.\nP or p for Patient.\nG or g for a Guest:");
    scanf_s("%c", &work);



    if (work == 'e' || work == 'E')
    {
        printf("The total revenue earned for the day:%.2lf\n", revenue);
        loop == SENTINEL;
    }
    if (work == 's' || work == 'S')
        staff();

}


}


int staff(void)
{
    double clientC = 2.0;
    printf("Please enter the number of hours they were in the parking     
    garage:\n");
    scanf_s("%lf", &hours);
    printf("The charge for staff members is $2.00 a day.\n Your charge is 
    $%.2lf\n", clientC);
    revenue +=clientC;
    return(0);
}

0 个答案:

没有答案