# Thread: Help writing calculator program (newbie)

1. ## Help writing calculator program (newbie)

Hi, I've recently begun to learn how to program in C, I wrote a calculator program that worked so I decided to update it, but my updated source has errors that I don't know how to fix. My situation is this, my compiler tells me that I have to fix Error A, after I fix Error A, it tells me I have to fix Error B, when I fix Error B, it tells me I have to fix Error A again. Very confusing. Anyhow this is the source I have written.

-=begin=-

#include <stdio.h>
#include <string.h>

main()

{
int number1, number2, choice5;

printf("Welcome to Calculator 0.2, written by Danny Two, this is an update to an already crappy program, Hope you enjoy!\n\n");
printf("[2] Subtraction\n");
printf("[3] Multiplication\n");
printf("[4] Division\n");

scanf("%d", &choice5);

if {
(choice5 == 1);
scanf("%d", &number1);
scanf("%d", &number2);
printf("Sum is %d\n", number1 + number2);
}

if {
(choice5 == 2);
printf("You have chosen Subtraction, Please enter the two numbers you wish to subtract\n");
scanf("%d", &number1);
scanf("%d", &number2);
printf("Sum is %d\n", number1 - number2);
}

if {
(choice5 == 3);
printf("You have chosen Multiplication, Please enter the two numbers you wish to multiply\n");
scanf("%d", &number1);
scanf("%d", &number2);
printf("Sum is %d\n", number1 * number2);
}

if {
(choice5 == 4);
printf("You have chosen Division, Please enter the two numbers you wish to divide\n");
scanf("%d", &number1);
scanf("%d", &number2);
printf("Sum is %d\n", number1 / number2);
}

return 0;

}

-=end=-

The error messages I am getting for that is...

calc02.cpp
C:\c++ programs\Calculator\Calculator 02\calc02.cpp(20) : error C2059: syntax error : '{'
C:\c++ programs\Calculator\Calculator 02\calc02.cpp(20) : error C2143: syntax error : missing ';' before '{'
C:\c++ programs\Calculator\Calculator 02\calc02.cpp(28) : error C2059: syntax error : '{'
C:\c++ programs\Calculator\Calculator 02\calc02.cpp(28) : error C2143: syntax error : missing ';' before '{'
C:\c++ programs\Calculator\Calculator 02\calc02.cpp(36) : error C2059: syntax error : '{'
C:\c++ programs\Calculator\Calculator 02\calc02.cpp(36) : error C2143: syntax error : missing ';' before '{'
C:\c++ programs\Calculator\Calculator 02\calc02.cpp(44) : error C2059: syntax error : '{'
C:\c++ programs\Calculator\Calculator 02\calc02.cpp(44) : error C2143: syntax error : missing ';' before '{'
Error executing cl.exe.

When I add a ";" before the "{"s all the syntax errors about the "{" and the missing ";" will be gone, but instead it adds

error C2059: syntax error : ';'

to the equation and I dunno what to do after that.

Any help greatly appreciated.

2. The structure of your if statement is wrong. Here, look at this:
Code:
```if (something == 1)
{
printf ("Something is 1\n");
}```
note the position of the brackets, and semi-colons. Compare it to your version, and try again.

3. Thanks, Hammer! It worked. Thanks for helping out a n00b heh. I'll never make that mistake again.

Once again thanks.

4. >Thanks, Hammer!
No problem