Similar to the Loop thread just posted(help please)
Hey guys, I am new to programming, and for the sake of learning how to create loops constructively I have tried to make a very simple calculator program (below) however I am having issues making it loop or 'restart'.
I read the Loop thread posted 2hours ago, however I didnt get any resolve so hence the new thread
I can create 'for'/'while' and 'do while' loops but not with this switch statement inside (the program will just crash(compiles fine))
My code is ment to;
1. Ask for a input(number)
2. Ask for a 2nd
3. ask for +, -, or *
4. Supply answer and restart
*It works fine without the for loop.
*This is just to understand loops more practically
Code:
#include <stdio.h>
int main(int argc, char *argv[]){
int numb1;
int numb2;
int sum;
int choice;
int restart;
int restart1 = 1;
for (restart = 0; restart > restart1; NULL) {
printf("Enter a number:\n");
scanf("%d", &numb1);
printf("Enter a second number:\n");
scanf("%d", &numb2);
printf("Press 1 for Adding the two numbers\n");
printf("Press 2 for Subtraction\n");
printf("Press 3 for Multiplication\n");
scanf("%d", &choice);
switch (choice) {
case 1:
sum = numb1 + numb2;
printf("The result is %d\n", sum);
break;
case 2:
sum = numb1 - numb2;
printf("The result is %d\n", sum);
break;
case 3:
sum = numb1 * numb2;
printf("The result is %d\n", sum);
break;
default:
printf("You did enter a valid choice\n");
break;
}
}
}
Thanks