unsure why my code prints out this

when i run my code and enter in x, it prints out 124.28. can someone tell me why? Im trying to assign a letter a number and im not even sure if im doing it right so ignore that part. thanks

#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
int main()

{

char option;
char x = 0;
char X = 0;
double total = 0;



do{
cout << "Welcome to the coffee shop! we offer:" << endl;
cout << "C - Coffee = $1.29" << endl;
cout << "J - juice = $1.50" << endl;
cout << "S - Soda = $ 1.00" << endl;
cout << "T - Tea = $1.39" << endl;
cout << "M - Manager special = $2.99" << endl;
cout << "X - to end order" << endl;
cout << "What drink would you like? Press C,J,S,T,MS or X to finish order" << endl;
cin >> option;

if (option == 'C' || 'c')
{
total += 1.29;

}
if (option == 'J' || option == 'j')
{
total += 1.5;

}
if (option == 'S' || option == 's')
{
total += 1.00;

}
if (option == 'T' || option == 't')
{
total += 1.39;

}
if (option == 'M' || 'm')
{
total += 2.99;

}
if (option == 'X' || option == 'x')
{

total += option;
cout << "You have fninished your order, Your total is $" << total << endl;
return 0;
}

}

while (option != x || option != X);



return 0;
Hi,

Please always use code tags. http://www.cplusplus.com/articles/z13hAqkS/

Can you explain the purpose of this line? total += option;

Also, this one doesn't look like the others : if (option == 'C' || 'c')

The variables x and X aren't used.

There are the tolower() or toupper() functions, which can be used, so you don't have to compare lower and upper case all the time.

Consider making your if statements (not the first one) else if, then provide an else to catch bad input. Also check out the switch statement.

Good Luck !!
Topic archived. No new replies allowed.