Need a little help for class

Hey everyone, I'm running a bit behind in class and I feel like I've almost finished this program. If anyone could point me to the right direction in getting this fixed, it'd be most appreciated.

Edit: I almost forgot to describe it. I need to write a program that allows the user to input a value and a capacity equal to the amount a room can hold. If the amount of people is too much for how big the room is, then it will say so.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
using namespace std;
int main( )
{

int people; 
int capacity;
int answer;

do{
cout << "Enter the amount of people: ";
cin >> people; 

cout << "Enter the room capacity: ";
cin >> capacity;

if (people >= capacity)
{
cout << "Meeting cannot be held.\n";
cout << "(capacity - people) need to be removed.\n";
}
else
{
cout << "Meeting can be held.\n";
cout << "(capacity - people) more people can be added.\n";
}

cout << "Again? (y or n): ";
cin >> answer;

} while(ans == 'y' || ans == 'Y');

system("PAUSE");
return 0;
} 
Last edited on
Tell me, what's meant to happen if the number of people is exactly the same as the number of people the room can hold?
I suppose the program would state that it's still okay for that amount of people to be in the room. As long as it doesn't go over whatever the limit stated is, it should be fine.
Also, shouldn't "(capacity - people) more people can be added.\n"; be replaced with an actual value for the number of people that need to be removed?
Yeah probably, I'm just not sure how to go about doing that.
The program does not calculate the number of people to be removed / added because your hint is inside the quotes.

You need to have those as separate statements with some more variables.

The variable ans is not declared. The compiler should have told you that.

You can make use of the std::toupper function (#include <locale> to use it) so you don't have to test ans twice, because it converts it to upper case.

I prefer this method to quit out of something:

1
2
3
4
5
6
7
8
9
bool Quit = false;

while (!Quit) {
//your code here

//user wants to quit
Quit = true;
}


HTH
Last edited on
Yeah, I'm not sure why I didn't catch the "ans" not being declared, I fixed it and the program is working now for the most part. However, now the problem seems to be that it wont say how many people can be added or need to be removed.

Also TheIdeasMan, if I use that method for quiting out of the program in clase, then my teacher wont believe I done it and will give me a 0. It happend to me earlier in the year when I had someone help me, they showed me how to incorporate arrays and she gave me a 0 for it. It's a pain.
@VincentVindicated

Well that sucks, you cannot demonstrate a better way of doing things, and are forced to stagnate with whatever the teacher deems as being suitable.

I guess she is trying to stop cheats - I suppose the only thing to do is declare to her that you belong to this forum. As long as she can see we haven't done you homework for you, it might be OK. The downsides are: She might not be bothered with that ( busy enough already); She will see what you didn't know.

However, now the problem seems to be that it wont say how many people can be added or need to be removed.


TheIdeasMan wrote:
The program does not calculate the number of people to be removed / added because your hint is inside the quotes.

You need to have those as separate statements with some more variables.


You have to put in code to calculate these.
Yeah, it does suck and not only that but whenever I ask for assistance, she tells me "I believe students will figure out how to do it on their own," or even say "Yeah there are problems that need to be fixed."

I feel like she doesn't even care if I pass or fail her class, which is terrible because this is the last class I need to earn my certificate.

Anyways, yeah I'll look into it, thanks.
Topic archived. No new replies allowed.