1. Calculator loop problem

Hi, I am trying to create a calculator program that only allows the user three attempts, my actul calculator program works fine however i cant figure out where the while loop should go here is my attempt. When i compile it it runs through the calculator but stops after taken the second num!

Code:
```#include <stdio.h>

main()

{

int num1, num2, sum;

int count=0;

char operation,dummy;

printf("Enter first number: "); /*retrieves first number from user */

scanf("%d", &num1);

printf("Enter operation (+ or - or * or /): "); /* retrieves operation from user */

scanf("%c%c%c",&dummy,&operation,&dummy);

printf("Enter second number: "); /*retrieves second number from user */

scanf("%d", &num2);

while(count<3)

if (operation == '+'){
sum = num1 +  num2;
printf("The sum of %d and %d is %d", num1,num2, sum);

} /* if operation is +, will add numbers and show answer */

if(operation == '-'){
sum = num1-num2;
printf("Subtracting %d from %d is %d", num2,num1,sum);

}/* if operation is -, will subtract and show answer */

if (operation == '*'){
sum = num1 * num2;
printf("Multiplying %d by %d is %d", num1, num2, sum);

} /* if operation is *, will multiply and show answer */

if (operation == '/'){
sum = num1 / num2;
printf("Dividing %d by %d is %d", num1, num2, sum);

}
/* if operation is /, will divide and show answer */

count=count+1;

return 0;

}```

2. Be explicit when you declare main. It's int main(void), not just main(). Read this link.

The general format for a while loop is
Code:
```while (some condition is true)
{
}```
Everything that you want repeated 3x needs to go in those curly braces. I always use curly braces when working with loops and if statements, even when I don't need them, so it's clear what I want repeated and what I don't. It's a helpful visual clue. Proper code formatting and indentation would also help you spot this problem, as you would see that only the if (operator == '+') part is currently inside the while. Many editors and IDEs offer an auto-indent feature to help with this.

3. Thanks for the help and advice!quite stupidly i dont indent it properly until i have it finished!which defeats the purpose really!

I have it pretty much working now but it prints the answer three times instead of three attempts!

4. Originally Posted by Laika1986
I have it pretty much working now but it prints the answer three times instead of three attempts!
Put everything, and I mean everything, that you want repeated inside the while loop. What isn't getting repeated that should be? Put that in the loop too.

Study this code until you understand how it works.
Code:
```#include <stdio.h>

int main(void)
{
int num1, num2, count=0;
char operation,

while(count<3)
{
printf("Enter <number> < + - / *> <number> : ");
scanf("%d %c %d", &num1, &operation, &num2);

switch (operation)
{
case '+' :
printf("The sum of %d and %d is %d\n", num1, num2, num1 + num2);
break;
case '-' :
printf("Subtracting %d from %d is %d\n", num2,num1, num1 - num2);
break;
case '*' :
printf("Multiplying %d by %d is %d\n", num1, num2, num1 * num 2);
break;
case '/' :
printf("Dividing %d by %d is %d\n", num1, num2, num1 / num2);
break ;
default :
printf("Invalid operation\n");
}
count=count+1;
}
return 0;
}```
The good news is you can't turn this in, since it's published here and your teacher is likely to find it.

6. My teacher would also think that I am about 4 lessons ahead so i do appreciate your input but it's irrelevant. Ill close the thread myself if possible

It was one thread to be fair and how have i ignored it?