Teyn

koso

Dec 2nd, 2020
846
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. //Lopputyö
  2.  
  3.  
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. int roomnumber;
  8. int amountofvisitors;
  9. int occupiedpl;
  10. int room;
  11. int totalvisitors;
  12. int totalcost = 0;
  13. char answer;
  14. const int maxrooms = 15;
  15. const int minrooms = 1;
  16.  
  17. bool rooms[maxrooms];
  18. int main()
  19. {
  20.     answer = 'y';
  21.     for(int i=0; i<=maxrooms; i++){
  22.          rooms[i] = false;  
  23.         }
  24.    
  25.     while (answer = 'y')
  26.     {
  27.         cout << "Rooms currenntly available\n";
  28.         for(int i=0; i<maxrooms; i++){
  29.             if(rooms[i] == false){
  30.                 cout << i << " ";
  31.             }
  32.         }
  33.  
  34.         int roomnumber = 0;
  35.         cout << "\n\nWhich room would you like to book? ";
  36.         cin >> roomnumber;
  37.  
  38.         while(roomnumber >= maxrooms || roomnumber < minrooms){
  39.         cout << "Please enter a valid room number!\n";
  40.         cout << "Which room would you like to book? ";
  41.         cin >> roomnumber;
  42.         }
  43.    
  44.         if(rooms[roomnumber] == true){
  45.             cout << "This room is already booked! Would you like to try to book another room? (y/n) ";
  46.             cin >> answer;
  47.         }
  48.        
  49.         if(rooms[roomnumber] == false)
  50.         {
  51.             cout << "How many nights will you be staying?";
  52.             cin >> amountofvisitors;
  53.             totalvisitors = amountofvisitors;
  54.             rooms[roomnumber] = true;
  55.             occupiedpl++;
  56.            
  57.             cout << "Room " << roomnumber << " booked for " << amountofvisitors << ". Cost so far: ";
  58.             totalcost += (totalvisitors * 100);
  59.             cout << totalcost << "\n\n";
  60.            
  61.         cout << "Would you like to book another room? (y/n) ";
  62.         cin >> answer;
  63.         if(answer == 'n') break;
  64.         }
  65.  
  66.     }
  67.    
  68.     cout << "Room booking is finished! Total cost: " << totalcost;
  69.  
  70. system("PAUSE");
  71. return 0; }
Advertisement
Add Comment
Please, Sign In to add comment