• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Where is the error?

mOeeOm

Platinum Member
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;
}
 
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 {
 
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 { ?
 
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
 
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***

🙁
 
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.
 
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)
 
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.
 
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.
 
Back
Top