Program Not running right

Hi there, could you help me out? I am making a program "for fun", and it stops taking input from the keyboard after I answer "Have you been fired from a job before?". After that, it spits out the next 3 questions, then says FIRED! and quits the program. I have tried to debug it, but I don't see what's wrong. Here is the code: Thanks for helping!


#include <iostream>
#include <cmath>
using namespace std;



int main()
{
int age, fired, n, N, jobs, hours, pets, relationships,favorite, kids;
int name, name2, name3, Nappy, Num, Nuts;
double pay, nuts;

cout<<"This is a survey from Nappy Num Nuts."<<endl;
cout<<"This program determines if you will be hired or fired!"<<endl;

cout<<"What is your age?"<<endl;
cin>>age;
if(age<16 || age>70)
{
cout<<"FIRED!"<<endl;
exit(0);
}

cout<<"Have you been fired from a job more than once? (y/n)"<<endl;
cin>>fired;
if(fired!=n || fired!=N)
{
cout<<"FIRED!"<<endl;
exit(0);
}

cout<<"How many jobs have you had so far?"<<endl;
cin>>jobs;
if(jobs>=5)
{
cout<<"FIRED!"<<endl;
exit(0);
}

cout<<"How much pay (per hour) do you want to start with?"<<endl;
cin>>pay;
if(pay>=11.00)
{
cout<<"FIRED!"<<endl;
exit(0);
}

cout<<"How many hours are you willing to work per week?"<<endl;
cin>>hours;
if(hours<20 || hours>70)
{
cout<<"FIRED!"<<endl;
exit(0);
}

cout<<"How many pets do you have?"<<endl;
cin>>pets;
if(pets<1 || pets>3)
{
cout<<"FIRED!"<<endl;
exit(0);
}

cout<<"How many relationships have you had?"<<endl;
cin>>relationships;
if(relationships>4)
{
cout<<"FIRED!"<<endl;
exit(0);
}

cout<<"How many children do you have?"<<endl;
cin>>kids;
if(kids>5)
{
cout<<"FIRED!"<<endl;
exit(0);
}


cout<<"How many Nappy Num Nuts do you have?"<<endl;
cin>>nuts;
if(nuts<2 || nuts>50)
{
cout<<"FIRED!"<<endl;
exit(0);
}

cout<<"Out of the following, what is your favorite nut? (Enter only one nut by its number)"<<endl;
cout<<"Cashew(1), Peanut(2), Pistachio(3), Almond(4), Pecan(5), Macadamia(6), Num(7)."<<endl;
cin>>favorite;
if(favorite!=7)
{
cout<<"FIRED!"<<endl;
exit(0);
}

cout<<"Almost done!"<<endl;
cout<<"What is the name of the company you are applying to work for?"<<endl;
cout<<"Note: company name MUST be spelled correctly!"<<endl;
cin>>name >> name2 >> name3;
if(name!=Nappy || name2!=Num || name3!=Nuts)
{
cout<<"FIRED!"<<endl;
exit(0);
}
else
cout<<"HIRED!"<<endl;



return 0;
}


closed account (o3hC5Di1)
Hi there,

First off, try to put code-tags around your code next time, it makes it easier for us to read.
Also, applying some kind of indentation would be desirable, but tabs get deleted here so that's not always convenient.

In this part of your code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
int main()
{
int age, fired, n, N, jobs, hours, pets, relationships,favorite, kids;
int name, name2, name3, Nappy, Num, Nuts;
double pay, nuts;

cout<<"This is a survey from Nappy Num Nuts."<<endl;
cout<<"This program determines if you will be hired or fired!"<<endl;

cout<<"What is your age?"<<endl;
cin>>age;
if(age<16 || age>70)
{
cout<<"FIRED!"<<endl;
exit(0);
}

cout<<"Have you been fired from a job more than once? (y/n)"<<endl;
cin>>fired;
if(fired!=n || fired!=N)
{
cout<<"FIRED!"<<endl;
exit(0);
}


You declare n and N as ints.
However, you don't assign them any value, and y/n is not an int.

So try to declare n and N as a char type, then set them to 'n' and 'N' respectively:

char n='n', N='N';

And don't forget to remove them from the list if int declarations.

Hope that helps.

All the best,
NwN
Last edited on
thanks; it didn't work, so I just cut out the question and added a few others instead. Thanks for the help though!
closed account (o3hC5Di1)
Hi there,

The reason it didn't work is because of this line:

if(fired!=n || fired!=N)

Once you say char n='n', N='N';, the expression should become if (fired == n || fired == N), Sorry I missed that.

All the best,
NwN
I believe other issues are the fact that you have declared everything in your program as an int. Unless you planned on just entering numbers for the entire program, or valid characters, you're going at your program all wrong. I'd suggest you look into strings to be able to do what you expect. What happens when you enter your name and try to print it out? Does it print out your name or just one character? Does it print characters at all? Or just numerical values. I believe you should try to work on your program because it's not doing what you're expecting, trust me.
Topic archived. No new replies allowed.