..use do{} while{}..
for example..
#include
main(){
int choose;
double a,b,c;
printf("Enter 7 if you want to use the calculator. Otherwise,type any character.\n");
scanf("%d",&choose);
do{
if (choose==7){
printf("Press 1 for addition.\n");
printf("Press 2 for subtraction.\n");
printf("Press 3 for multiplication.\n");
printf("Press 4 for division.\n");
scanf("%d",&choose);
if (choose==1){
printf("Enter the addends\n");
scanf("%lf %lf", &a,&b);
c=a+b,
printf("The sum of %lf and %lf is %lf.\n",a,b,c);
}else if(choose==2){
printf("Enter the minuend and subtrahend\n");
scanf("%lf %lf", &a,&b);
c=a-b,
printf("The difference of %lf and %lf is %lf.\n",a,b,c);
}else if(choose==3){
printf("Enter the multipliers\n");
scanf("%lf %lf", &a,&b);
c=a*b,
printf("The product of %lf and %lf is %lf.\n",a,b,c);
}else if(choose==4){
printf("Enter the dividend and divisor\n");
scanf("%lf %lf", &a,&b);
c=a/b,
printf("The quotient of %lf and %lf is %lf.\n",a,b,c);
}else{
printf("You have entered an invalid digit.\n");}
printf("If you want to continue,press 7 and choose again from 1 to 4.\n");
printf("Do you want to exit? Enter any key.\n");
scanf("%d",&choose);
}
}while(choose==7);
}
Chat with our AI personalities
To return the exp. or const to the main fumction.
void display is the function name in which we want to perform some task or it might be to display something. But it has got its residence in the main() function that means that function's inputs are being supplied from the main(). void doesn't return anything so function call is made in main() which doesn't return anything back to it.
The normal exit of program is represented by zero return value. If the code has errors, fault etc., it will be terminated by non-zero value. In C++ language, the main() function can be left without return value. By default, it will return zero. To learn more about data science please visit- Learnbay.co
It means end the function. Functions automatically end when execution reaches the end of the function, but you can return from a function at any point within the function with a return statement. If the function returns a value to its caller, you must provide a reachable return statement along with the value you wish to return.
A return statement exits the function in which it is declared and gives control to the calling code. Returning from the main function exits the program and gives control to the execution environment.