1
죄송합니다, 여기에 초보자의 비트 :평가 부울 ++
나는 날 하루의 시간에 따라 장거리 전화의 비용을 결정하기 위해 연습 프로그램에서 일하고 있어요 주 ... 나는 do-while 루프를 돌았고 중첩 된 브랜치를 사용하여 평일과 주말을 분리하려고 시도했다.
그러나 컴파일하고 실행할 때 if 및 else if 중첩 된 문은 건너 뛸 때 상관없이 내가 평가하려고하는 부울에 해당하는 Chars를 삽입해도 상관 없습니다. 내가 여기서 뭘 놓치고 있는지 이해하기 위해 고심하고있다. 지시 사항에 따르면주의 요일은 두 가지 변수로 저장해야합니다 : Mo Tu We Th Fr Sa Sa.
do
{
//have user input day of week of call
printf("\nOn what day was the call made? (Mo, Tu, We, Th, Fr, Sa, or Su) ");
scanf("%c%c", &day1, &day2);
//branch for weekday vs weekend vs invalid input
if (((day1 == 'M') && (day2 == 'o')) || ((day1 == 'T') && (day2 == 'u')) || ((day1 == 'W') && (day2 == 'e')) || ((day1 == 'T') && (day2 == 'h')) || ((day1 == 'F') && (day2 == 'r')))
{
//determine if phone call was made at hi or low rate times
printf("At what time was your call made? (HH MM - with 08 00 representing 8:00 AM and 18 30 representing 6:30 PM) ");
scanf("%f %f", &call_time_hour, &call_time_minute);
call_time_hour = call_time_hour + (call_time_minute/60);
printf("%f", call_time_hour);
}
else if (((day1 == 'S') && (day2 == 'a')) || ((day1 == 'S') && (day2 == 'u')))
{
printf("What was the duration of your call? ");
scanf("%d", &call_duration);
//calculate total cost of call
cost_of_call = call_duration * 0.15;
printf("%s %.2lf", "The cost of this call was $", cost_of_call);
}
calls_made--;
printf("%d", calls_made);
}while (calls_made > 0);
따라서, 예를 들어, 내가 컴파일하고 프로그램을 실행하고 호출이 된 날로서 "사"를 입력 할 때, 그것은 다음 'calls_made--'단계로 직접 이동.
이 C.이 C 더 같습니다이 경우
는 요일 스캔하기 전에 입력 스트림을 취소? – Ron
아니요, C++ – Michael
입니다. C++에서는 [std :: cout] (http://en.cppreference.com/w/cpp/io/cout) 및 [std :: cin] (http : // ko)를 사용해야합니다. .cppreference.com/w/cpp/io/cin). – boriaz50