I am trying to make a program that will display the mode of a Note in the key of C. For those who don't know music theory, this is what I want to happen:
If the user inputs the char 'A', display "Aeolian"
If 'B', display "Locrian"
If 'C', display "Ionain"
else display "INVALID"
The problem I am having is that the compiler will only acknowledge the first if statement ( which is for if the user inputs 'A' ). If I were to input 'B' or 'C', the compiler still goes right to the else statement. If I write a similar kind of program using integers, it works just fine, so I am assuming there is something wrong with my declaration, or I'm not writing the structure of multiple if statements. I guess run the code and you'll see what I mean, unless the answer is right in front of my face. Here is the Code:
#include <iostream>
using namespace std;
int main()
{
char input;
cout << " Type a character (A-C) to see its corresponding mode in C \n\n ";
cin >> input;
if (input == 'A')
{
if (input == 'B')
{cout << "Locrian";
return 0;}
How can that possibly make any sense? The outer code block at line 2 will only execute if input is 'A'. If input is 'A', how can it possibly be 'B' as well?
You have the if statements for 'B' and 'C' inside the block for when 'A' is true.
Also, you don't need to put return 0 in each branch, just put it once in the end.