Advertisement
DrAungWinHtut

menu.cpp

Nov 17th, 2024
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.31 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdlib> //system
  3. using namespace std;
  4. float calculateArea(float l, float w);
  5. void area();
  6. void baydin();
  7. void menu();
  8. int main()
  9. {
  10.     while (1)
  11.     {
  12.         system("cls");
  13.         menu();
  14.     }
  15.     return 0;
  16. }
  17.  
  18.  
  19. void menu()
  20. {
  21.     int ans = -999;
  22.     cout << "Menu System" << endl;
  23.     cout << "=============" << endl;
  24.     cout << "1 - Baydin" << endl;
  25.     cout << "2 - Calculate Area " << endl;
  26.     cout << "3 - Exit Program" << endl;
  27.     cout << "Please choose 1,2,3: ";
  28.     cin >> ans;
  29.     switch (ans)
  30.     {
  31.     case 1: baydin(); break;
  32.     case 2: area();  break;
  33.     case 3: exit(0); break;
  34.     default: break;
  35.     }
  36. }
  37.  
  38. void area()
  39. {
  40.     float length = 0.0F;
  41.     float width = 0.0F;
  42.     float area = 0.0F;
  43.     cout << "Enter Length ";
  44.     cin >> length;
  45.     cout << " Enter Width ";
  46.     cin >> width;
  47.     area = calculateArea(length, width);
  48.     cout << "The area is " << area << endl;
  49.     system("pause");
  50. }
  51.  
  52. float calculateArea(float l, float w)
  53. {      
  54.     return w * l;
  55. }
  56.  
  57. void baydin()
  58. {
  59.     string name = "";
  60.     int sum = 0;
  61.     int luck = -999;
  62.  
  63.     cout << "Please Enter Your Name: ";
  64.     cin >> name;
  65.     for (char ch : name)
  66.     {
  67.         sum += int(ch);
  68.     }
  69.     luck = sum % 3;
  70.     if (luck == 0)
  71.     {
  72.         cout << "bad" << endl;
  73.     }
  74.     if (luck == 1)
  75.     {
  76.         cout << "normal" << endl;
  77.     }
  78.     if (luck == 2)
  79.     {
  80.         cout << "excellent" << endl;
  81.     }
  82.     system("pause");
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement