Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.85 KB | None | 0 0
  1. //Programming Homework #3
  2.  
  3. #include "stdafx.h"
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. //Creates a function called header.
  8. void header()
  9. {
  10.     cout << "Room | Capacity | Enrollment | Empty Seats | Filled/Not Filled" << endl;
  11. }
  12.  
  13.  
  14. //Creates a function called EndOfProgram.
  15. int EndOfProgram()
  16. {
  17.     cout << "Try another room? (Y/N): ";
  18.     char end;
  19.     cin >> end;
  20.  
  21.     //if statement to restart from main function if Y or y is pressed (if end is equal to Y or y).
  22.     if (end == 'Y' || end == 'y')
  23.         return 1;
  24.  
  25.     //else if statement to quit the program if N or n is pressed (if end is equal to N or n).
  26.     else if (end == 'N' || end == 'n')
  27.         return 0;
  28.    
  29.     //else statement to return to EndOfProgram if the input anything other than Y, y, N, or N.
  30.     else
  31.     {
  32.         cout << "Invaid input" << endl;
  33.         EndOfProgram();
  34.     }
  35. }
  36.  
  37.  
  38.  
  39. //Main function.
  40. int main()
  41. {
  42.     //Asks for room number, then applies it to integer roomnum.
  43.     cout << "Room: ";
  44.     int roomnum;
  45.     cin >> roomnum;
  46.  
  47.     //Asks for the capacity, then applies it to integer roomcap.
  48.     cout << "Capacity: ";
  49.     int roomcap;
  50.     cin >> roomcap;
  51.  
  52.     //Asks for the enrollment, then applies it to integer roomenr.
  53.     cout << "Enrollment: ";
  54.     int roomenr;
  55.     cin >> roomenr;
  56.  
  57.     //Makes an integer called empty, then makes it equal to the capacity minus the enrollment.
  58.     int empty = roomcap - roomenr;
  59.  
  60.     //Calls back to the header function.
  61.     header();
  62.  
  63.     //If else statement to display a different result depending on if the room is full or not.     
  64.     if (empty>0)
  65.         cout << roomnum << "      " << roomcap << "           " << roomenr << "            " << empty << "            Not Filled" << endl;
  66.     else
  67.         cout << roomnum << "      " << roomcap << "           " << roomenr << "            " << empty << "            Filled" << endl;
  68.  
  69.     //Calls the EndOfProgram function.
  70.     if(EndOfProgram() == 1)
  71.         main();
  72.     else
  73.         return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement