I agree MK... But I don't wish to be banned before day two..it's just not stylish
Do you just try to determine whether they're doing it for a class and make a judgement call or actually ask?
Since from his reply and the explaining quickly the way he did., i believe he did figure this out and I will demonstrate here the proper way and why it was shooting the wrong answer, for google searchs for the resource .
Before this begins, I would like to make a quick note to harley...i'm going to be changing something in my version..check out what it is..and see if you notice the redundancy removal.
Original:
Code:
//declare variables
char comboType = ' ';
double comboPrice = 0.0;
double orderTotal = 0.0;
//input data
cout << "Enter item ordered [A/B/C/D] or T to calculate total: ";
cin >> comboType;
comboType = toupper(comboType);
while (comboType != 'T')
{
cout << "Enter item ordered [A/B/C/D] or T to calculate total: ";
cin >> comboType;
orderTotal += comboPrice;
switch (comboType)
{
case 'A':
comboPrice = 4.25;
break;
case 'B':
comboPrice = 5.75;
break;
case 'C':
comboPrice = 5.25;
break;
case 'D':
comboPrice = 3.75;
break;
//end switch
}
// end while
}
//display output
if (comboType = 'T')
{
cout << "Please pay this amount: " << orderTotal << endl;
}
and now, a bit cleaner...
Code:
//declare variables
char comboType = ' ';
double comboPrice = 0.0;
double orderTotal = 0.0;
//input data
cout << "Enter item ordered [A/B/C/D] or T to calculate total: ";
cin >> comboType;
while (comboType != 'T'){
comboType = toupper(comboType);
switch (comboType){
case 'A':
comboPrice = 4.25;
break;
case 'B':
comboPrice = 5.75;
break;
case 'C':
comboPrice = 5.25;
break;
case 'D':
comboPrice = 3.75;
break;
//end switch
}
cin >> comboType;
orderTotal += comboPrice;
//end while
}
//display output
if (comboType = 'T'){
cout << "Please pay this amount: " << orderTotal << endl;
In the first code, within the loop, comboType was being redefined as 0.0 before the cases were defined, so no matter what, he would be missing exactly 5.75...or the first entry he put in during the sequence of B B A D D D where B == 5.75... since the first
Code:
orderTotal += comboPrice;
was ran before the actual defintion of "B" was run, ...just 0.0 = 0.0 + 0.0 and thus the first entry would always be missed, whether this be B B A D D or A B A D D or C B A D D etc..
Hope this helps, if you have any questions, just ask. ( And for the expert vets here, please feel free to clarify)
EDIT: Sorry for the spaces instead of TABS..nano formats oddly(But they should be spaced to standard tabs )...