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;
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.
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.
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.