The assignment is: Add a do-while loop so that the program will continue prompting the user to see if another calculation is to be done.
I can't seem to figure out how to do the do-while loop. (where to put it) What I have gives runs but not 100% correct, so I'm assuming it is a minor detail. Please help.
Thanks
Code:
#include <stdio.h>
int main()
{
// Variable Declarations
float num1, num2, result;
char sel, sel2, Y;
do
{
// Input: Getting 2 numbers
printf("Enter 2 numbers: ");
scanf("%f %f",&num1, &num2);
//Displaying the menu
printf("\nMenu:\n");
printf("A ----- Addition\n");
printf("S ----- Subtraction\n");
printf("M ----- Multiplication\n");
printf("D ----- Division\n");
// Input: Getting the user's selection
printf("\nEnter the letter corresponding to the calculation to be performed: ");
scanf(" %c",&sel);
if(sel=='A' || sel=='a')
{
result = num1+num2;
printf("\nThe addition is: %.2f\n",result);
}
else if(sel=='S' || sel=='s')
{
result = num1-num2;
printf("\nThe subtraction is: %.2f\n",result);
}
else if(sel=='M' || sel=='m')
{
result = num1*num2;
printf("\nThe multiplication is: %.2f\n",result);
}
else if(sel=='D' || sel=='d')
{
result = num1/num2;
printf("\nThe division is: %.2f\n",result);
}
else
{
printf("\nInvalid Choice\n");
}
printf("Would you like to perform another calculation?");
scanf(" %c", &sel2);
}while(sel2=Y);
return 0;
}