C assigment
unknown
c_cpp
2 years ago
2.7 kB
5
Indexable
#include<stdio.h> #include<stdlib.h> void home(char*); void calculator(); void menu(); void endmessage(); int main() { char choice = '0'; do { switch (choice) { case '0': system("cls"); mainmenu(&choice); break; case 'A': system("cls"); menu(); choice = '0'; break; case 'B': system("cls"); calculator(); choice = '0'; break; case 'C': system("cls"); break; default: system("cls"); printf("Invalid option, please choose A, B or C.\n"); printf("\nWrite 'Back' if you want to get back to the main menu!.\n "); scanf(" %c", &choice); while (choice != "Back") { printf("Invalid option, please choose A, B or C.\n"); printf("\nWrite 'Back' to go back to the Home Page "); scanf(" %c", &choice); } choice = '0'; } } while (choice != '3'); system("cls"); endmessage(); return 0; } void calculator() { float a, b; char n; char choice; printf("Calculator:"); printf("\n"); printf("\n"); printf("\nEnter the desired operation: "); scanf("%f %c %f", &a, &n, &b); if (n == '+') printf("\n%.0f+%.0f=%.2f\n", a, b, a + b); else if (n == '*') printf("\n%.0f*%.0f=%.2f\n", a, b, a * b); else if (n == '/') if (b == 0) printf("MATH ERROR"); else printf("\n%.0f/%.0f=%.2f\n", a, b, a / b); while (choice != 'q') { printf("\nPlease press 'q' to get back to the main menu: "); scanf(" %c", &choice); } } void menu() { char choice; printf("Edibles and their Prices::\t"); printf("\n1-Chips - 5 EGP"); printf("\n2-Pepsi - 8 EGP"); printf("\n3-7 UP - 8 EGP"); printf("\n4-Bubbly - 15 EGP"); printf("\n5-Milka - 30 EGP"); printf("\n6-Lays - 25 EGP"); printf("\n7-Choclate Milkshake - 50 EGP"); printf("\n8-Sunday - 20 EGP"); printf("\n9-Happy Meal - 55 EGP"); printf("\n10-Mountain Dew - 8 EGP"); while (choice != "Back") { printf("\nPlease type 'Back' to go to Home Page."); scanf(" %c", &choice); } } void endmessage() { printf("Enjoy!"); } void home(char* choice) { printf("The menu:"); printf("\n"); printf("\n"); printf("Type one of the options, please:\n"); printf("A - Show Menu.\n"); printf("B - Calculator.\n"); printf("C- Exit.\n"); printf("choose A,B or C:"); scanf(" %c", &*choice); }
Editor is loading...