Where is the error?

mOeeOm

Platinum Member
Dec 27, 2004
2,588
0
0
I keep getting an error telling me:

Error E2379 new.c 39: Statement Missing ; in function main *** 1 Errors in compile ***

Anyways here is the code, please help me find it :(

#include <stdio.h>
#define Balance 100
#define pinnumber 2006

int main(void)
{
int pin;
int depo;
int wdrl;
int balance;
int transtype;
int deposit;
int withdrawl;
printf("Please enter your pin number");
scanf("%d", &pin);
if (pin == pinnumber){
printf("\n You have entered a correct pin");
printf("\n Your current balance is %d", Balance);
printf("\n Please choose a transaction type: \n");
printf("\n1.Deposit \n2.Withdrawl \n3.Transfer \n");
scanf("%d", &transtype);
if (transtype == 1)
{
printf("\n Please enter how much you would like to deposit: ");
scanf("%d", &depo);
deposit = Balance + depo;
printf("\n Your new balance is = %d", deposit);
}
else if (transtype == 2)
{
printf("How much would you like to withdraw:");
scanf("%d", &wdrl);
if (wdrl > Balance)
{

printf("You cannot withdraw more than your current balance");
}
else
}
withdrawl = Balance - wdrl;
printf("\n Your new balance is = %d", withdrawl);
}
}
return 0;
}
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
printf("You cannot withdraw more than your current balance");
}
else
}
withdrawl = Balance - wdrl;
printf("\n Your new balance is = %d", withdrawl);
}

see the else? you have } instead of a {
 

mOeeOm

Platinum Member
Dec 27, 2004
2,588
0
0
Originally posted by: dighn
printf("You cannot withdraw more than your current balance");
}
else
}
withdrawl = Balance - wdrl;
printf("\n Your new balance is = %d", withdrawl);
}

see the else? you have } instead of a {

So which } should I change to { ?
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
Originally posted by: mOeeOm
Originally posted by: dighn
printf("You cannot withdraw more than your current balance");
}
else
}
withdrawl = Balance - wdrl;
printf("\n Your new balance is = %d", withdrawl);
}

see the else? you have } instead of a {

So which } should I change to { ?

the } after else

what you want is a block statement. { ... } is a block statement, } ... } is not
 

mOeeOm

Platinum Member
Dec 27, 2004
2,588
0
0
if (wdrl > Balance)
{
printf("You cannot withdraw more than your current balance");
}
else
{
withdrawl = Balance - wdrl;
printf("\n Your new balance is = %d", withdrawl);
}
}
return (0);
}

The new one, now it gives me this error: Compound statement missing } in function main
Warning W8070 error.c 42: Function should return a value in function main.

***1 Errors in Compile***

:(
 

igowerf

Diamond Member
Jun 27, 2000
7,697
1
76
Originally posted by: mOeeOm
if (wdrl > Balance)
{
printf("You cannot withdraw more than your current balance");
}
else
{
withdrawl = Balance - wdrl;
printf("\n Your new balance is = %d", withdrawl);
}
}
return (0);
}

The new one, now it gives me this error: Compound statement missing } in function main
Warning W8070 error.c 42: Function should return a value in function main.

***1 Errors in Compile***

:(

Put another } before return (0);

When you're coding, make sure to indent your code. I prefer not to use tabs because they're sized differently in different editors. I usually go with 2 or 3 spaces.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Each { needs a matching } and you're missing one.

Count them. Match them. Make them agree with each other.
 

mOeeOm

Platinum Member
Dec 27, 2004
2,588
0
0
Originally posted by: igowerf
Originally posted by: mOeeOm
if (wdrl > Balance)
{
printf("You cannot withdraw more than your current balance");
}
else
{
withdrawl = Balance - wdrl;
printf("\n Your new balance is = %d", withdrawl);
}
}
return (0);
}

The new one, now it gives me this error: Compound statement missing } in function main
Warning W8070 error.c 42: Function should return a value in function main.

***1 Errors in Compile***

:(

Put another } before return (0);

When you're coding, make sure to indent your code. I prefer not to use tabs because they're sized differently in different editors. I usually go with 2 or 3 spaces.


<3

She works now :) I should have this done by wednesday. Just wondering, why wasn't it working before as it is? (this is my first time programming)
 

igowerf

Diamond Member
Jun 27, 2000
7,697
1
76
Originally posted by: mOeeOm
<3

She works now :) I should have this done by wednesday. Just wondering, why wasn't it working before as it is? (this is my first time programming)

The { and } group together chunks of code (blocks) that should be executed together based on certain conditions established by the if() statements. They're like parenthesis in math equations:
(5 + 2 * 2 + (3 + 5)

In that example, you don't have enough information to properly solve the problem. It could be (5+2)*2+(3+5), or (5 + 2 * 2) + (3+5) and each gives a different answer. Since you were missing a }, the compiler couldn't figure out how your code was supposed to be grouped.

By indenting your code, you can tell where the opening and closing braces should be.
 

NuclearNed

Raconteur
May 18, 2001
7,871
361
126
If you are using MSVC++ to compile this, you can hit <CTRL>{ while the cursor is positioned on an opening or closing bracket, and the development environment will show you the other bracket, if it exists. That makes it really easy to track down bugs like this.

Of course, the other easy way is to indent your code properly so that bugs like this stand out.