sted
Rising Star
I'm currently learning C++ and I have to finish off a program, but I'm having a bit of an issue getting an if statement to work correctly. The problem I'm encountering is that I'm trying to get the program to output a value based on the users input, but it always gives one particular value which is incorrect. I've narrowed it down to what seems to be the program always outputting the value of the last part of the statement, rather than the corresponding value of the user input.
In other words (as I'll show below), if the user inputs a, the program should output 50, but instead it outputs the value of c regardless of input.
Unfortunately the break; code doesn't work for if statements like it does for switch, which would have presumably made this easier. Not to mention I have to include the if statement (I need at least one included in the program).
Here is what it looks like at the moment:
In other words (as I'll show below), if the user inputs a, the program should output 50, but instead it outputs the value of c regardless of input.
Unfortunately the break; code doesn't work for if statements like it does for switch, which would have presumably made this easier. Not to mention I have to include the if statement (I need at least one included in the program).
Here is what it looks like at the moment:
Code:
void buy_tickets()
{
system("cls");
cout<<"\nPlease choose the type of ticket you would like to purchase:";
cout<<"\n\n\t\t\t a - Day Ticket";
cout<<"\n\n\t\t\t b - Weekend (camping)";
cout<<"\n\n\t\t\t c - Weekend (non-camping)";
cin.get();
cin.ignore();
if (cin=="a"){
cout<<a;
cin.ignore();
cin.get();
}
else if (cin=="b") {
cout<<b;
cin.ignore();
cin.get();
}
else {
cout<<c;
cin.ignore();
cin.get();
}
}