If/ Else Statement Not Working

I know i'm a noob to C++ programming, and i may be completely missing what i'm doing, but i have researched and cannot find solution to this. When you type in 'Yes' on line 81, it does not even recognize the actions in the first loop; It just ends the program. Please help!

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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <iostream>

#include <istream>




using namespace std ;

int main()
{
	int ItemPrice ;
	float StateTax ;
	float CityTax ;
	double Product ; //int cannot make decimals, this possibly can.
	double Product2 ; 
	double Product3 ;
	double Product4(void) ;
	
	

//item
	      cout <<"Price of Item?" << endl;
          cout <<"?"  ;
	      cout <<"$";
	cin >> ItemPrice;  //input of the car they want to buy/ variable

	      cout <<""<<  endl; //skip line

//statetax

	      cout <<"State Tax?"<< endl;
	      cout <<"$";

    cin >> StateTax; //input of the state tax/ variable
	      cout <<""<<  endl; //skip line

//product

	  

	      cout <<"The State Tax is "<< ItemPrice * StateTax << endl;   /* printf: %f is for floats, %lf is for doubles */
	                        
	                           Product = ItemPrice * StateTax;

	              system("pause");

	       cout <<"This means that the the car plus the sales tax is "<<"$"<< Product + ItemPrice << endl;


//citytax
	       cout <<"City Tax?"<< endl;
	       cout <<"$";

	cin >> CityTax; //input of the state tax/ variable

	Product2 = ItemPrice * CityTax; 
	       cout <<"The City Tax is "<< Product2 << endl;



	                         Product3 = Product2 + Product + ItemPrice ;

	       cout <<"This means that the the car plus the taxes is "<< Product2 + Product + ItemPrice  << endl;
	               system("pause");

   
	   char Choice ;	 
	   float LuxurySalesTax ;
	   float LuxuryTax(void) ;

	        cout <<""<<  endl; //skip line

	

	        cout <<"Is the item an Luxury Item?  (Yes/No)"<< endl;
		
        cin >> Choice ; 

		
		if(Choice == 'Yes')
		{
			
		   

			      

			cout << "" << endl ;

			cout << " What is the Luxury tax? " << endl; 

			cout << "" << endl ;

		cin >> LuxurySalesTax ;

		    cout << "" << endl ;


		    cout << "Your LuxarySalesTax is"<< LuxurySalesTax ;

		    cout << "" << endl ;

		           

		            return 0;

		}
		
		else (Choice == 'no') ;
		
			system("pause");

			return 0;
		        
		
		 

	         
		
}
choice is defined as having type char. It can contain only one character. So there is no any sense to compare choice with a character literal

if(Choice == 'Yes')

They are unequal.
Last edited on
closed account (Dy7SLyTq)
first of all... too much white space. secondly line 3 isnt needed. line 18 shouldnt have a (void). finally (well not finally but most importantly as it addresses your question) look up std:: string. use that instead of char
I just fixed a little things in there and made your if/else statement work. You had Char which accepts value of just one Character. Code isn't perfect or clean, but I just made it so it would work.

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
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "stdafx.h"
#include <iostream>
#include <istream>

using namespace std;

int main()
{

	int ItemPrice ;
	float StateTax ;
	float CityTax ;
	double Product ; //int cannot make decimals, this possibly can.
	double Product2 ; 
	double Product3 ;
	double Product4(void) ;
	
	

//item
	      cout <<"Price of Item?: ";
		  cin >> ItemPrice;  //input of the car they want to buy/ variable
		  cout <<  endl; //skip line

//statetax

	      cout <<"State Tax?: ";
		  cin >> StateTax; //input of the state tax/ variable
          cout << endl; //skip line

//product

	  

	      cout <<"The State Tax is "<< ItemPrice * StateTax << endl;   /* printf: %f is for floats, %lf is for doubles */
	                        
	                Product = ItemPrice * StateTax;

	              system("pause");

	       cout <<"This means that the the car plus the sales tax is "<<"$"<< Product + ItemPrice << endl;


//citytax
	       cout <<"City Tax?: ";
		   cin >> CityTax; //input of the state tax/ variable
	
					Product2 = ItemPrice * CityTax; 

	       cout <<"The City Tax is "<< Product2 << endl;



	                Product3 = Product2 + Product + ItemPrice;

	       cout <<"This means that the the car plus the taxes is "<< Product2 + Product + ItemPrice  << endl;
	               system("pause");

   
	   char Choice;	 
	   float LuxurySalesTax;
	   float LuxuryTax(void);

	        cout << endl; //skip line
			cout <<"Is the item an Luxury Item?(Y/N): ";
		    cin >> Choice; 

		
		if(Choice == 'Y')
		{
			  						      
			cout << "" << endl;
			cout << " What is the Luxury tax?: "; 
			cin >> LuxurySalesTax;
			cout << endl;
			cout << "Your LuxarySalesTax is"<< LuxurySalesTax;
		    cout << endl;
		         		        
		}
		
		else (Choice == 'N');
		{
			system("pause");
		}
			
		
	return 0;
}
Last edited on
Okay I see, thanks so much for the help guys!!!
Topic archived. No new replies allowed.