I'm working on a program that reads data from the user (in the form of number of people in a hotel room) and outputs whether or not there is a vacancy.
The code is as follows:
1) #include "stdafx.h"
2) #include <iostream>
3)
4) int main ()
5) {
6) using namespace std;
7) using namespace std;
8) cout << "How many people checked into room 1?" << endl;
9) int nPeople1;
10) cin>> nPeople1;
11) using namespace std;
12) cout << "How many people checked into room 2?" << endl;
13) int nPeople2;
14) cin>> nPeople2;
15) using namespace std;
16) cout << "How many people checked into room 3?" << endl;
17) int nPeople3;
18) cin>> nPeople3;
19) using namespace std;
20) cout << "How many people checked into room 4?" << endl;
21) int nPeople4;
22) cin>> nPeople4;
23) cout << "How many people checked into room 5?" << endl;
24) int nPeople5;
25) cin>> nPeople5;
26) if (nPeople1 == 0||nPeople2 == 0||nPeople3 == 0||nPeople4 == 0||nPeople5 == 0)
27) cout<< "VACANCY"<< endl;
28) else
29) cout<< "NO VACANCY"<< endl;
30)
31) return 0;
32) }
If possible, I would like to break the main function into 2 separate functions. One called IsOcc that gathers the data, and the main function to process and output the vacancy status.
A single function to query the status of all the rooms from the user isn't really practical if the status of each room is stored in a separate variable local to main(). Is that way of storing the room status mandatory in the assignment?
You should remove most of your
Code:
using namespace std;
directives. You only need that once in main(), or, if it is meant to affect more than one function, outside of a function body, right after the #includes.
HTH
Please use code tags the next time you post code, and no line numbers.
Ah, and... Welcome to CodeGuru!
Last edited by Eri523; December 2nd, 2010 at 03:28 PM.
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Bookmarks