I am have created a simple calculator program using switch statements which has been successful. But I am having trouble creating a do while loop at the bottom which loops the calculator function I have tried to create, which is my main goal to ask the user if they want to repeat the calculator program using a do while loop. Any help with be appreciated.
#include <stdio.h>
char math;
float number1;
float number2;
void calculator();
int selection = 0;
int main()
{
void calculator(){
printf(" enter the math operation: ");
scanf("%c", &math);
printf("Enter two numbers: ");
scanf("%f%f", &number1, &number2);
switch(math)
{
case '+':
printf("number1+number2=%.2f",number1+number2);
break;
case '/':
printf("number1/number2=%.2f",number1/number2);
break;
case '-':
printf("number1-number2=%.2f",number1-number2);
break;
case '*':
printf("number1*number2=%.2f",number1*number2);
break;
default:
printf ("Wrong character entered.");
}
}
Start of the do while function which asks the user if they want to repeat the program.
do{
printf{"\n\n - Do you want to repeat the program?"};
printf("\n1 - Yes");
printf("\n2 - No");
scanf("%i", &selection );
}
while (selection != 2);
calculator();
return 0;
}