Enter one variable, then the program skips to end

Hey all. I'm helping a friend with his code, and everything compiles fine, but when I try to run it, it only lets me enter the first input, and then it skips to the end of the program. any ideas? let me know if you want to see the code.
I'm not sure how you expect us to figure out your issue without your code? So yes, indeed we would like to see it.
sorry, its just a little long

# include <iostream>
using namespace std;

int main ()
{
char firstName;
char lastName;
double hoursWorked;
double hourlyRate;
double grossPay;
double taxWithheld;
char unionFee;
char extraInsurance;
double takeHomePay;
double numberOfDependants;

cout << "What is your first name?" << endl;
cin >> firstName;
cout << "What is your last name?" << endl;
cin >> lastName;

cout << "How Many Hours worked?\n";
cin >> hoursWorked;

cout << "What is your hourly rate?\n";
cin >> hourlyRate;

if (hoursWorked <= 40)
{
grossPay = (hoursWorked * hourlyRate);
}
else // Hours worked is >40
{
grossPay = (40 * hourlyRate) + (((hoursWorked - 40) * hourlyRate) * 1.5);
}

cout << "Are you a union member? Hit y for yes or n for no.\n";
cin >> unionFee;

if (unionFee == 'y')
{
takeHomePay = (grossPay - 10);
}
else
{
takeHomePay = grossPay;
}

cout << "Do you have Extra Health Insurance? Hit y for yes or n for no.\n" << endl;
cin >> extraInsurance;

if (extraInsurance == 'y')
{
cout << "How many dependants live live with you?\n" << endl;
cin >> numberOfDependants;
if (numberOfDependants < 3)
{
takeHomePay = (grossPay - 35);
}
else
{
takeHomePay = grossPay;
}
}
else
takeHomePay = grossPay;

cout << "Your total pay is " << takeHomePay << " dollars\n";

return 0;

}
It is you are trying to enter a string to an object that cna kepp only one symbol because it is declared as

char firstName;
ahhhh I see. What do you suggest I use in its' place?
Use either a character array or standard class std::string.
It is more suitable to use std::string.
Last edited on
ok. so, for say char firstName, what do i replace that with? string firstName? neither of our classes have gone over this yet. he was using double firstName before I took a look at it...
Personally, I leave out the using namespace std; and just use std::string instead, but I believe using string in conjunction with using namespace std; is the correct way to do it.

A string is an array of chars. Useful for names or sentences, etc, but stick to using char for things like y/n inputs.
hm. alright, so now it looks like this:
string firstName;
string lastName;
double hoursWorked;
double hourlyRate;
double grossPay;
double taxWithheld;
char unionFee;
char extraInsurance;
double takeHomePay;
double numberOfDependants;

but i'm getting an error...Error 1 error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
You should include header <string>
woooo! victory! thanks a lot to all of you. it's working swimmingly now. Couldn't have done it without y'all.
Topic archived. No new replies allowed.