So I've been coding for nearly 5 days and managed to make this calculator with some effort. Might not be the best syntax arrangement but it works. Problem is every time it does a calculation, it closes down and I have to open it up again manually.
I'd like to put a loop in the code so that it repeats this line...
Code:
printf("1 for adding up, 2 for subtraction, 3 for multiplication and 4 for division.\n");
scanf("%i", &selector);
...when it's done a calculation so that I can redo it without having to press F10 on Dev-C++ again.
And I have literally NO CLUE how to include the while (or for?) argument in it in order to achieve that. I'm literally clueless. I don't know how to make it work so I need to ask you guys how to do it.
Thanks a lot.
Code:
#include <stdio.h>
main()
{
int selector, alg1, alg2;
printf("1 for adding up, 2 for subtraction, 3 for multiplication and 4 for division.\n");
scanf("%i", &selector);
printf("Enter two operands:\n");
scanf("%i %i",&alg1, &alg2);
switch(selector)
{
case 1:
printf("%i + %i = %i", alg1, alg2, alg1 + alg2);
break;
case 2:
printf("%i - %i = %i", alg1, alg2, alg1 - alg2);
break;
case 3:
printf("%i * %i = %i", alg1, alg2, alg1 * alg2);
break;
case 4:
printf("%i / %i = %i", alg1, alg2, alg1 / alg2);
break;
default:
printf("Invalid");
}
}