Having a problem with my if/else statement's...

Ok, i am having a problem with my if/else statements and i can't figure out what it is.

I have a cin statement asking for an unknown variable, but no matter what i enter it always does the first and only if statement, then ends the program.

please help, here is my program so far:

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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include<iostream>
#include<math.h>
#include<iomanip>
  using namespace std;

void main()
{
	double P1, r1, t1, e1, total1;
	char unknown, var1, var2, var3, var4;
	e1=2.718281828459045;
	var1='T';
	var2='P';
	var3='r';
	var4='t';
	cout<<"Which variable is unknown in the formula, \"total = Pe^(rt)\" ? e is given.\n\n\n\n";
	cout<<"              Equation variable | What you should enter\n";
	cout<<"                                |  (Case sensitive)    \n";
	cout<<"              -----------------------------------------\n";
	cout<<"                    total       |          T           \n";
	cout<<"                      P         |          P           \n";
	cout<<"                      r         |          r           \n";
	cout<<"                      t         |          t           \n\n\n";
	cout<<"The unknown variable is:  ";
	cin>>unknown;
		if (unknown == var1 /*total*/)
		{
		cout<<"\nPlease enter P.\n";
		cin>>P1;
		cout<<"\nPlease enter r.\n";
		cin>>r1;
		cout<<"\nPlease enter t.\n";
		cin>>t1;
		total1=((P1)*(pow(double(e1), double(r1*t1))));
		cout<<fixed<<showpoint<<setprecision(2);
		cout<<"\nThe total must equal to "<<total1<<"\n\n";
		}
	    else if (unknown == var2 /*P*/)
		{
		cout<<"\nPlease enter total.";
		cin>>total1;
		cout<<"\nPlease enter r.";
		cin>>r1;
		cout<<"\nPlease enter t.";
		cin>>t1;
		P1=((pow(double(e1), double(r1*t1))*100)/total1);
		cout<<fixed<<showpoint<<setprecision(2);
		cout<<"\nThen P must equal to "<<P1<<endl;
		}
		else if (unknown == var3 /*r*/)
		{
		cout<<"\nPlease enter total.";
		cin>>total1;
		cout<<"\nPlease enter P.";
		cin>>P1;
		cout<<"\nPlease enter t.";
		cin>>t1;
		r1=((log(total1))/3);
		cout<<fixed<<showpoint<<setprecision(2);
		cout<<"\nThen r must equal to "<<r1<<endl;
		}
		else if (unknown == var4 /*t*/)
		{
		cout<<"\nPlease enter total.";
		cin>>total1;
		cout<<"\nPlease enter P.";
		cin>>P1;
		cout<<"\nPlease enter r.";
		cin>>r1;
		t1=((log(total1))/2);
		cout<<fixed<<showpoint<<setprecision(2);
		cout<<"\nThen t must equal to "<<t1<<endl;
		}

}



Last edited on
unknown = var1
This code means "set the value of the variable unknown to be the same as the value of the variable var1."

unknown==var1
This code means "is the value of the variable unknown the same as the value of the variable var1?"

You've used the top one. I suspect you meant the bottom one.
Last edited on
@Moschops

you were right but it still didn't change anything i just retried the program with the new changes and it still does it.

can somebody copy and paste it into MSV and see if theirs does it too.

P.S. i just edited the first post's code to what i have now with Moschops changes.
Actually disregard that last post... it turns out Moschops was correct, and i needed to create a new project in MSV in order for it to recognize the changes.

So thank you very much Moschops
Topic archived. No new replies allowed.