Hi guys, so in my program I need the user to input a "y" or "n" as a yes/no response, but I need the response to be counted as a numerical value. For example, if the user enters "y," then that means they have 1 set of stairs to climb. If they answer "n," then they have 0 set of stairs to climb. Then I want the program to take their response and add it up.
So if they have 1 (meaning they entered "y") set of stairs to climb at their house and then another set of stairs to climb at their destination, they have a total of 2 sets of stairs. Or they have 0 (meaning they entered "n") sets of stairs to climb at their house, and 1 set of stairs to climb at their destination. How do I get the program to add these up?
Let me know if that needs some clarification. Thank you!
// Set number of stairs at origin
int y = 1; int n = 0;
cout << "Does the origin have more than 15 stairs (y/n)?\n"; // y = 1, n = 0
cin >> stair_user_origin;
// Set number of stairs at destination
cout << "Does the destination have more than 15 stairs (y/n)?\n";
cin >> stair_user_destination;
stair_total = stair_user_origin + stair_user_destination; // total set of stairs (0, 1, 2), additional $90 charge for each set of stairs
And so each set of stairs that they answer "y" for charges them an additional $90. What I don't get is how to take both answers and add them together as the calculator (which is what the program is supposed to be) later determines the total charge for the stairs.
Here is an example, using a char, of a function that gets a Y/N answer to study
1 2 3 4 5 6 7
// get an answer in the form 'y' or 'n'
char Yn_Answer(){
while(true) {
char answer(std::toupper(std::cin.get()));
if(answer == 'Y' || answer == 'N') return answer;
};
}