character to Int conversion error...

Jun 16, 2009 at 1:16am
Hello All,

Here is my program followed by the error. its almost complete but for some reason it doesnt like one of the last while statements that i entered. i will bold the string causing the error.

int main()
{

double reghours, taxamount, retirement, prenetpay, overtime, overtimepay, hourlywage, totalhours, taxes, netpay, grosspay ; // this defines each of the variables i will be working with.
char ch
reghours = 0;
std::cout << "Please enter number of regular hours worked :" ;
std::cin>>reghours;

while (reghours >= 41)
{
std::cout<< "Hours must be between 1 and 40. Please reenter hours worked :" ;
std::cin>> reghours; //this will prompt the user to enter the first hours 0-40.
}

while (ch >="A" && ch <="Z");
{
std::cout<< "Regular hours worked must be a numerical value between 1 and 40. Please reenter regular hours : ";
std::cin>>reghours;
}

std::cout<<"Please enter the number of hours worked over 40 if any : " ;
std::cin>> overtime; //this will give us the variable needed for the number of hours worked over 40.

while (overtime >=128)
{
std::cout<< "overtime cannot exceed 128 hours. Please reenter overtime hours: " ;
std::cin>>overtime;
}

std::cout<< "Please enter hourly pay rate: " ;
std::cin>> hourlywage; //this will give us the hourlywage variable.

overtimepay = overtime * 1.5 * hourlywage;

grosspay = (reghours * hourlywage) + overtimepay;
std::cout<< "The gross pay is: " << grosspay << std::endl;

retirement = 25; //this is the amount that will be withheld for the retirement fund.

taxes = .2; //this reflects the 20% that will need to be removed from gross pay as a result of taxes withheld.

prenetpay = grosspay - retirement; //this gives a dollar amount to deduct taxes from. Retirment is being done pre-tax.

taxamount = prenetpay * taxes; //this will give us the amount withheld for taxes.

std::cout<< "The amount of taxes withheld is : " << taxamount << std::endl;

netpay = prenetpay - taxamount;

std::cout<< "The total Net Pay is : " << netpay << std::endl;




The errors im receiving as a result are listed below. Any help is greatly appreciated.

c:\documents and settings\misty\my documents\visual studio 2008\projects\pay calc\pay calc\pay calc.cpp(13) : error C2146: syntax error : missing ';' before identifier 'reghours'
c:\documents and settings\misty\my documents\visual studio 2008\projects\pay calc\pay calc\pay calc.cpp(23) : error C2446: '>=' : no conversion from 'const char *' to 'int'
There is no context in which this conversion is possible
c:\documents and settings\misty\my documents\visual studio 2008\projects\pay calc\pay calc\pay calc.cpp(23) : error C2040: '>=' : 'int' differs in levels of indirection from 'const char [2]'
c:\documents and settings\misty\my documents\visual studio 2008\projects\pay calc\pay calc\pay calc.cpp(23) : error C2446: '<=' : no conversion from 'const char *' to 'int'
There is no context in which this conversion is possible
c:\documents and settings\misty\my documents\visual studio 2008\projects\pay calc\pay calc\pay calc.cpp(23) : error C2040: '<=' : 'int' differs in levels of indirection from 'const char [2]'
Build log was saved at "file://c:\Documents and Settings\Misty\My Documents\Visual Studio 2008\Projects\Pay Calc\Pay Calc\Debug\BuildLog.htm"
Pay Calc - 5 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Jun 16, 2009 at 1:20am
There's a semicolon missing after char ch.

Did you actually take a look at your while condition? I suggest you do.
Jun 16, 2009 at 1:44am
helios,

i appologize but i am extremly brand new to c++. im taking my first programming class ever and am only in week 3. so with that said, if you dont mind, may i ask for a little more detail as to what i did wrong in my while statement?

Thanks Much
Jun 16, 2009 at 1:49am
You're taking input into one variable but checking the value of a different variable.
Jun 16, 2009 at 1:50am
perhaps you could maybe help me to understand then how i can change that. im trying to tell the program that if the user enters a letter vs. a number, that the program should then state that its not ok and that instead to please reenter the numerical value.

again i appologize for being so new to this, but its just not making much sense to me where im going wrong.
Jun 16, 2009 at 1:56am
maybe ive figured a litte more of it out, ,but im still coding wrong. heres what i tried to change it to. i dont want u to think im just lookingn for the answer, just the way to figure it out.

heres what i tried....

while (reghours = ch >="A" && ch <="Z");
{
std::cout<< "Regular hours worked must be a numerical value between 1 and 40. Please reenter regular hours : ";
std::cin>>reghours;
}

im still getting errors here, but i feel like maybe im more on the right track.
Jun 16, 2009 at 1:58am
Okay, think about it this way: what does your std::cout statement says? Does it match what the condition says?
Jun 16, 2009 at 2:03am
my cout statement says that (or at least this is what im trying to make it say) if the user enters any letter at all, then i want the program to tell them thats not ok and to reenter, as opposed to if they enter a letter it crashing my program.

so from the way im looking at it, the condition of it being a letter in my while statement, would then match up to the cout statement that tells them its not ok.
Jun 16, 2009 at 2:16am
ok still working hard at it. heres what i did now...

char ch = 'a';
char chz = 'z';
reghours = 0;
std::cout << "Please enter number of regular hours worked :" ;
std::cin>>reghours;

while (reghours >= 41);
{
std::cout<< "Hours must be between 1 and 40. Please reenter hours worked :" ;
std::cin>> reghours; //this will prompt the user to enter the first hours 0-40.
}

while (ch >= 'a' && chz <= 'z');
{
std::cout<< "Value must be a number between 1 and 40. Please reenter hours worked : ";
std::cin>> reghours;
}



it likes this fine, but when i run the program, i type in any letter, and then it pops up my cout statement, BUT then it wont let me enter a value at all. it just sits there and ignores anything i type.
Jun 16, 2009 at 2:54am
You don't want the ';' after your while loops. Also, you still aren't checking the correct conditions...I would suggest making a flowchart or at least writing down what you want it to do, then coding it.
Topic archived. No new replies allowed.