Else without a previous if

I'm just starting out at C++ and I keep getting the error: 'else' without a previous 'if' even though I'm sure it should work.
Here's my code:

http://cpp.sh/7rwhc
If you have multiple statements running as part of the if/else condition, you need to enclose those statements in curly braces.

1
2
3
4
5
6
if {
statements
}
else if {
statements
}
it's not working
looks like I cannot connect to the website
please post the code here (copy pasting)

also please use tags

edit :
I can connect...here's a possible fix if it is to your liking

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
	if ( serviceType == 'p'||'p' )
	{ //you need this if it has more than one thing going on in if
		double xxx ; 
	     		ofstream xxx;
		xxx.open ("final_bill_Platnum.txt") ;
		xxx<< "Account Number: "<< accountNum << endl <<  "Type of Service: " <<serviceType << endl <<
		"Number of minutes you used during the morning : " << MorningMin << endl << "Number of minutes you used during the morning : " << nightMin << endl <<
		 "Amount Due 1 Day = SAR " << amountDue << endl ;
	}	
	else if  ( serviceType == 'G'||'g' ) 
	{
		double yyy ; 
	     		ofstream yyy ;
		yyy.open ("final_bill_gold.txt") ;
		yyy<< "Account Number: "<< accountNum << endl <<  "Type of Service: " <<serviceType << endl <<
	"Number of minutes you used : " << GMmin << endl <<
		 "Amount Due 1 Day = SAR " << amountDue << endl;
	}
Last edited on
do those conditions work?
looks to me like it would translate to

if x == 'G' (true or false, ok)
OR
'g' (true, 'g' is not zero)

Or am I misreading this?


Last edited on
Instead this, maybe? Or convert the input to upper or lower and check that.

serviceType == 'P' || serviceType =='p'

Giving the same name to a double variable and a filestream object is probably also causing an error.

1
2
double xxx ; 
ofstream xxx;
Topic archived. No new replies allowed.