I have never posted to a forum before. I am taking a beginning C++ prgmming class. I am getting the error "error C2181: illegal else without matching if " I have tried everything I can think of to fix it, I can't tell if its a syntax error (such as misplaced ;) or logic error. The following is my code. I've only included the part that is giving me error. I am sorry if this is the wrong place for this post. Please direct me to the correct one and thank you for your help

[

#include <iostream>
#include <iomanip>
//#include <fstream>

using namespace std;
  // declare const
	const double CHK_SERV_CHRG = 25.00;
	const double SAV_SERV_CHRG = 10.00;
	const double CHK_ABOVE_MIN_INT = .03;
	const double CHK_BELOW_MIN_INT = .05;

int main ()
{
	    // declare variables
	char AcctType;
	int AcctNum;
	double CurrentBal;
	double MinBal;
	double OverMinBal;
	double Interest = 0;

  cout << fixed << showpoint << setprecision(2); 
   cout << "Enter Bank account number: ";
   cin >> AcctNum; 
   cout << "Enter account type c for checking or s for savings: ";
   cin >> AcctType;
   cout << "Enter current balance: " << "$ " ;
   cin >> CurrentBal;
   cout << "Minimum Balance required: " << "$ ";
   cin >> MinBal;
   cout << endl;
  
   {  
    if (AcctType == 'c' && CurrentBal < MinBal)
	CurrentBal -= CHK_SERV_CHRG;
cout << "Account Number: " << AcctNum << endl;	
cout << "Checking account below allowed minimum balance of: " << MinBal << endl;
cout << "Service Charge of: " << "$ " << CHK_SERV_CHRG << endl; 
cout << "Current Balance: " << CurrentBal << endl;
   }
 else 
{
   Interest = CurrentBal * CHK_ABOVE_MIN_INT; 
	CurrentBal += Interest;
cout << "Checking account above minimum balance of: " << MinBal << endl;
cout << "Checking account earned the following interest: " <<  "$ " << Interest << endl;
	cout << "Current Balance: " << CurrentBal << endl;	
   }
{ 
if (AcctType == 'c' && CurrentBal < MinBal)
CurrentBal -= CHK_SERV_CHRG;

The structure of your if statement itself is not correct. As a result, the else is not associating with it properly (it's a technical thing, I won't confuse you with it). The opening brace should be after the if statement.

//example if - else structure
if (/* condition */)
{
  /* statements to execute if true */
}
else
{
  /* statements to execute if false */
}

A posting suggestion:
Use [code] ... code tags ... [/code] they make your code easier to read, if the code is formatted properly.

I have never posted to a forum before. I am taking a beginning C++ prgmming class.

It shows. You didn't bother to read the Member Rules and made a bad post...

Start by formatting your code so you can follow it. This error is almost always because of misplaced braces and formatting shows very quickly where the error is. It also makes code readable for others (like us) that didn't write it.

It shows. You didn't bother to read the Member Rules and made a bad post...

Start by formatting your code so you can follow it. This error is almost always because of misplaced braces and formatting shows very quickly where the error is. It also makes code readable for others (like us) that didn't write it.

Sorry for the bad post. I did find some introduction material about using the code. Was there anything else in the post that was wrong and I need to find out about?
Thanks for your help.
"T"

Really, it's just the tags. Misuse of, or missing, code tags is a big faux pas around here.

When I want to put the code in the post I'm supposed to click on the # button?. Thats what I got out of the info.
Theresa

Really, it's just the tags. Misuse of, or missing, code tags is a big faux pas around here.

I'm not sure what you mean by "# button". But if you look in the new post toolbar in both quick and advanced post modes, you'll see a [code] button. All you need to do is click that, then type between the opening and closing tags, or just type them in yourself:

[code] ... your code here ... [/code]

Thanks for the info. I will probably have another question for the forum later today. I'll be sure to use the tags.

"T"

You missed a opening bracket after this line: if (AcctType == 'c' && CurrentBal < MinBal) What IDE are you using? A lot of them (like visual studio, or code::blocks) have features to auto-format your code (indent it), so you don't have to worry about it yourself.

You missed a opening bracket after this line: if (AcctType == 'c' && CurrentBal < MinBal) What IDE are you using? A lot of them (like visual studio, or code::blocks) have features to auto-format your code (indent it), so you don't have to worry about it yourself.

This program is now working. Thank you for your reply. I am using Visual Studio 2008 and I will look for the auto format option.

"T"

I am using Visual Studio 2008 and I will look for the auto format option.

In this order:
ctrl-a
ctrl-k
ctrl-f

done.

Thank you.

"T"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.