Help with if then statements

I am working on a simple program that finds the tuition amounts for students. I prompt the user to enter i for instate or o for out of state. And if the user enters i then tuition amount would equal 3000 or if the user enters o then the tuition amount would equal 4500. The problem is when I print tutionAmount my results are o. No matter what letter I enter?

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
#include <iostream>

using namespace std;

int main()
{
string i;
string o;
string tuitionStatus;
int    tuitionAmount;

cout << "\n";
cout << "\t\t\tThe University of Guiness\n" << endl;


cout << "Please enter i for instate or o for out of state: ";
cin  >> tuitionStatus;
cout << endl;

if      (tuitionStatus == i)
            tuitionAmount = 3000;
			             
else if (tuitionStatus == o)
            tuitionAmount = 4500;

cout << tuitionAmount << endl;
}
Last edited on
initialize your string objects
1
2
string i = "i"
string o = "o"


you could also use chars instead of string objects
Last edited on
You could do as Oleg said or you could use string literals in the if statements directly and get rid of the two variables i and o.

 
if (tuitionStatus == "i")

Thank you
Topic archived. No new replies allowed.