Teyn

c++

Dec 2nd, 2020
1,410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. //Lopputyö
  2.  
  3.  
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. int roomnumber;
  8. int amountofnights;
  9.  
  10. int room;
  11. int totalvisitors;
  12. int totalcost = 0;
  13. char answer;
  14. const int maxrooms = 15;
  15. const int minrooms = 0;
  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 >> amountofnights;
  53.             totalvisitors = amountofnights;
  54.             rooms[roomnumber] = true;
  55.        
  56.             cout << "Room " << roomnumber << " booked for " << amountofnights << ". Cost so far: ";
  57.             totalcost += (totalvisitors * 100);
  58.             cout << totalcost << "\n\n";
  59.            
  60.         cout << "Would you like to book another room? (y/n) ";
  61.         cin >> answer;
  62.         if(answer == 'n') break;
  63.         }
  64.  
  65.     }
  66.    
  67.     cout << "Room booking is finished! Total cost: " << totalcost;
  68.  
  69. system("PAUSE");
  70. return 0; }
Advertisement
Add Comment
Please, Sign In to add comment