Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <ctype.h>
- int choice;
- void hienMenu(){
- printf("\n*****Arithmetic Program*****");
- printf("\n 1.Add");
- printf("\n 2.Subtract");
- printf("\n 3.Multiply");
- printf("\n 4.Devide");
- printf("\n 5.Quit");
- }
- void tinhtoan(){
- float x,y;
- printf("\nEnter the first number: "); scanf("%f", &x);
- printf("\nEnter the second number: "); scanf("%f", &y);
- switch(choice){
- case 1:
- printf("\nThe result %.0f + %.0f is %.6f", x,y,x+y); break;
- case 2:
- printf("\nThe result %.0f - %.0f is %.6f", x,y,x-y); break;
- case 3:
- printf("\nThe result %.0f x %.0f is %.6f", x,y,x*y); break;
- case 4:
- printf("\nThe result %.0f : %.0f is %.6f", x,y,x/y); break;
- }
- }
- int main(){
- do{
- hienMenu();
- printf("\nPlease enter your choice (1-5): ");
- scanf("%d", &choice);
- switch(choice){
- case 1: tinhtoan(); break;
- case 2: tinhtoan(); break;
- case 3: tinhtoan(); break;
- case 4: tinhtoan(); break;
- case 5: return 0; break;
- }
- fflush(stdin);
- if(choice>=1&&choice<=5){
- printf("\nContinue? (Y/N) ");
- char choice2 = getchar();
- switch(tolower(choice2)){
- case 'y': break;
- case 'n': return 0; break;
- default: break;
- }
- }
- else{
- printf("\nIncorect!\n");
- }
- }while(choice!=5);
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement