please help with yes or no program

hey guys i need help with my code. i need help with yes or no question.
here is my code. what i need help is only 'y' or 'n' should work. when i enter 'y' than it will continue ask question but when i enter 'n' it will display You do not qualify for financial aid. so let say when i enter 'h' than it should give me an error.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
using namespace std;

int main()
{
	int currentIncome;
	char underGraduate;

	cout << "Are you an undergraduate student?";
	cin >> underGraduate;

	if (underGraduate == 'y')
	{
		cout << "What is your current yearly income?";
		cin >> currentIncome;

		if (currentIncome < 0)
		{
			cout << "Income must be greater than or equal to 0!\n";
		}
		else if (currentIncome <= 15000)
		{
			cout << "You qualify for $1000 in financial aid.\n";
		}
		else if (currentIncome > 15000)
		{
			cout << "You qualify for $500 in fiancial aid.\n";
		}
	}

	else
	{
		cout << "You do not qualify for financial aid\n";
	}

	
	system("pause");
	return 0;
}
There's some/many ways to do that, here is one of it
1
2
3
4
5
6
7
8
9
10
if(answ=='y'||asnw=='n'){
  if(answ=='y'){
     //your code
  }
  else{
    //your code if answ is 'n'
  }
}else{
  //show error
}

Or use switch case it's the easiest I think
1
2
3
4
5
6
7
8
9
10
11
12
switch(answ){
  case 'y':
  case 'Y':
    //your code
    break;
  case 'n':
  case 'N':
    //your code
    break;
  default:
    //show error
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
using namespace std;

int main()
{
   int currentIncome;
   char underGraduate;

   cout << "Are you an undergraduate student?";
   cin >> underGraduate;

   if (underGraduate == 'y' || underGraduate == 'n')
   {
      if (underGraduate == 'y')
      {
         cout << "What is your current yearly income?";
         cin >> currentIncome;
         if (currentIncome < 0)
         {
            cout << "Income must be greater than or equal to 0!\n";
         }
         else if (currentIncome <= 15000)
         {
            cout << "You qualify for $1000 in financial aid.\n";
         }
         else if (currentIncome > 15000)
         {
            cout << "You qualify for $500 in fiancial aid.\n";
         }
      }

      else if (underGraduate == 'n')
         {
            cout << "You do not qualify for financial aid\n";
         }
      
      
   }
   
   else
   {
      cout << "Please enter y or n only!\n";
   }


   system("pause");
   return 0;
}


does this seems right??
Topic archived. No new replies allowed.