#include <stdio.h>
#include <iostream>
using namespace std;
float cost, total;
bool loop(char item){
switch (toupper(item)) {
case A :
cost = 4.25;
return true;
case B :
cost = 5.57;
return true;
case C :
cost = 5.25;
return true;
case D :
cost = 3.75;
return true;
case T :
return false;
}
return true;
}
int main(){
char item;
do {
printf("
Enter Item Ordered [A/B/C/D] or T to calculate total:");
scanf("%c", &item);
total = total + cost;
} while (loop(item));
printf("Total Cost: $%f
", total);
}
让我输出这一进程:
$ ./Case3.o
Enter Item Ordered [A/B/C/D] or T to calculate total:a
Enter Item Ordered [A/B/C/D] or T to calculate total:
Enter Item Ordered [A/B/C/D] or T to calculate total:b
Enter Item Ordered [A/B/C/D] or T to calculate total:
Enter Item Ordered [A/B/C/D] or T to calculate total:a
Enter Item Ordered [A/B/C/D] or T to calculate total:
Enter Item Ordered [A/B/C/D] or T to calculate total:t
Total Cost: $28.139999
为什么是在第一次印刷版后印制的f
。 第一次从投入中抽取我两次。 那么,它如何计算5.24+5.57+5.24到28.14平等?