Simple input and output program that quits to soon. I cant find the problem, please take a look.
-
Hello all, I just wanted to post here because I can not figure this out. I run the program in debugging mode which does not help at all for this. Maybe I just dont know how to use the debugger correctly yet. The program compiles without any errors, but after you enter your name the program exits. I dont understand it. I looked over the code time and time again and cant figure it out. So here is the very short code listed below. I appreciate any feedback on the obvious error with my program.
#include <iostream>
#include <string>
#include <iomanip>using namespace std;
int main()
{//Global Declarations of Variables
double iovertime_hours=0;
double iovertime_pay=0;
double iovertime_extra=0;
int cname ;
int ihours ;
int iwage ;//Enter Employee Information
cout << "\n\nEnter the employee name = " ;
cin >> cname ;
cout << "Enter the hours worked = ";
cin >> ihours ;
cout << "Enter his or her hourly wage = ";
cin >> iwage ;// Determine if hours are greater than 40
if (ihours > 40)
{
//Do Calculations
iovertime_hours=ihours+40;
iovertime_pay=iwage-1.5 ;
iovertime_extra=iovertime_hours*iovertime_pay;// Display Employee Details cout << "\\n\\n"; cout << "Employee Name ............. = " << cname << endl ; cout << "Base Pay .................. = " << iwage\*40 << endl ; cout << "Hours in Overtime ......... = " << iovertime\_hours << endl ; cout << "Overtime Pay Amout......... = " << iovertime\_extra << endl ; cout << "Total Pay ................. = " << iovertime\_extra+(40\*iwage) << endl; }
else (ihours < 40); // Else hours are less than 40 hours
{
cout << "\n\n";
cout << "Employee Name ............. = " << cname << endl ;
cout << "Base Pay .................. = " << iwage*40 << endl ;
cout << "Hours in Overtime ......... = " << iovertime_hours << endl ;
cout << "Overtime Pay Amout......... = " << iovertime_extra << endl ;
cout << "Total Pay ................. = " << iovertime_extra+(40*iwage) << endl;
} // End of the primary if statement
return 0;
} //End of Int Main</pre>
-
Hello all, I just wanted to post here because I can not figure this out. I run the program in debugging mode which does not help at all for this. Maybe I just dont know how to use the debugger correctly yet. The program compiles without any errors, but after you enter your name the program exits. I dont understand it. I looked over the code time and time again and cant figure it out. So here is the very short code listed below. I appreciate any feedback on the obvious error with my program.
#include <iostream>
#include <string>
#include <iomanip>using namespace std;
int main()
{//Global Declarations of Variables
double iovertime_hours=0;
double iovertime_pay=0;
double iovertime_extra=0;
int cname ;
int ihours ;
int iwage ;//Enter Employee Information
cout << "\n\nEnter the employee name = " ;
cin >> cname ;
cout << "Enter the hours worked = ";
cin >> ihours ;
cout << "Enter his or her hourly wage = ";
cin >> iwage ;// Determine if hours are greater than 40
if (ihours > 40)
{
//Do Calculations
iovertime_hours=ihours+40;
iovertime_pay=iwage-1.5 ;
iovertime_extra=iovertime_hours*iovertime_pay;// Display Employee Details cout << "\\n\\n"; cout << "Employee Name ............. = " << cname << endl ; cout << "Base Pay .................. = " << iwage\*40 << endl ; cout << "Hours in Overtime ......... = " << iovertime\_hours << endl ; cout << "Overtime Pay Amout......... = " << iovertime\_extra << endl ; cout << "Total Pay ................. = " << iovertime\_extra+(40\*iwage) << endl; }
else (ihours < 40); // Else hours are less than 40 hours
{
cout << "\n\n";
cout << "Employee Name ............. = " << cname << endl ;
cout << "Base Pay .................. = " << iwage*40 << endl ;
cout << "Hours in Overtime ......... = " << iovertime_hours << endl ;
cout << "Overtime Pay Amout......... = " << iovertime_extra << endl ;
cout << "Total Pay ................. = " << iovertime_extra+(40*iwage) << endl;
} // End of the primary if statement
return 0;
} //End of Int Main</pre>
look at
else (ihours < 40);
{what do you think that semi-colon is doing ? if you remove it, which you should, you'll get a compile error with that statement as it is (so you have another change to make) ... is that enough of a clue ? 'g'
-
look at
else (ihours < 40);
{what do you think that semi-colon is doing ? if you remove it, which you should, you'll get a compile error with that statement as it is (so you have another change to make) ... is that enough of a clue ? 'g'
G, First off thanks for the response. I should have removed that semi-colon before posting here. I had it removed and added it right after I copied the entire source and pasted here. Without the semi-colon I am still stuck. The compile error I get is: overtime.cpp In function `int main()': 43 overtime.cpp expected `;' before '{' token So that is why I put the semi-colon after the else selection statement. I am still confused on how to correct the error that I obviously do not see. If you could provide another hint, I would be able to figure it out. Just need a point into the right direction. Thank you again. V/R Rob
-
Hello all, I just wanted to post here because I can not figure this out. I run the program in debugging mode which does not help at all for this. Maybe I just dont know how to use the debugger correctly yet. The program compiles without any errors, but after you enter your name the program exits. I dont understand it. I looked over the code time and time again and cant figure it out. So here is the very short code listed below. I appreciate any feedback on the obvious error with my program.
#include <iostream>
#include <string>
#include <iomanip>using namespace std;
int main()
{//Global Declarations of Variables
double iovertime_hours=0;
double iovertime_pay=0;
double iovertime_extra=0;
int cname ;
int ihours ;
int iwage ;//Enter Employee Information
cout << "\n\nEnter the employee name = " ;
cin >> cname ;
cout << "Enter the hours worked = ";
cin >> ihours ;
cout << "Enter his or her hourly wage = ";
cin >> iwage ;// Determine if hours are greater than 40
if (ihours > 40)
{
//Do Calculations
iovertime_hours=ihours+40;
iovertime_pay=iwage-1.5 ;
iovertime_extra=iovertime_hours*iovertime_pay;// Display Employee Details cout << "\\n\\n"; cout << "Employee Name ............. = " << cname << endl ; cout << "Base Pay .................. = " << iwage\*40 << endl ; cout << "Hours in Overtime ......... = " << iovertime\_hours << endl ; cout << "Overtime Pay Amout......... = " << iovertime\_extra << endl ; cout << "Total Pay ................. = " << iovertime\_extra+(40\*iwage) << endl; }
else (ihours < 40); // Else hours are less than 40 hours
{
cout << "\n\n";
cout << "Employee Name ............. = " << cname << endl ;
cout << "Base Pay .................. = " << iwage*40 << endl ;
cout << "Hours in Overtime ......... = " << iovertime_hours << endl ;
cout << "Overtime Pay Amout......... = " << iovertime_extra << endl ;
cout << "Total Pay ................. = " << iovertime_extra+(40*iwage) << endl;
} // End of the primary if statement
return 0;
} //End of Int Main</pre>
First a side comment on terminology.
rbwest86 wrote:
int main() { //Global Declarations of Variables double iovertime_hours=0; double iovertime_pay=0;
These are actually automatic (local) variables, not global. There is nothing wrong with this - you normally do want to use automatic variables rather than global whenever you can. Now to your question.
rbwest86 wrote:
int cname ; int ihours ; int iwage ; //Enter Employee Information cout << "\n\nEnter the employee name = " ; cin >> cname ;
Note that cname is an int. I would normally expect the response to the prompt to be a string. You are telling cin to expect only a number. Perhaps cname should be something like, oh, a std::string.
-
G, First off thanks for the response. I should have removed that semi-colon before posting here. I had it removed and added it right after I copied the entire source and pasted here. Without the semi-colon I am still stuck. The compile error I get is: overtime.cpp In function `int main()': 43 overtime.cpp expected `;' before '{' token So that is why I put the semi-colon after the else selection statement. I am still confused on how to correct the error that I obviously do not see. If you could provide another hint, I would be able to figure it out. Just need a point into the right direction. Thank you again. V/R Rob
ok, so, think about the syntax of an if then else statement your first test is if (hours > 40) you have two options at that error - (a) there can be no other conditions, in which case you only need the else, or (b) you want to test for maybe (hours < 20) for example ... Im presuming the first - so try this
else // (ihours < 40); Else hours are less than 40 hours
see what Ive done - Ive turned your (wrong) statement into a comment, ie, if hours and not > 40 they must then fall into the the 'everything else' code 'block' getit ? 'g'
-
G, First off thanks for the response. I should have removed that semi-colon before posting here. I had it removed and added it right after I copied the entire source and pasted here. Without the semi-colon I am still stuck. The compile error I get is: overtime.cpp In function `int main()': 43 overtime.cpp expected `;' before '{' token So that is why I put the semi-colon after the else selection statement. I am still confused on how to correct the error that I obviously do not see. If you could provide another hint, I would be able to figure it out. Just need a point into the right direction. Thank you again. V/R Rob
Look up the syntax for an if(){}else{} statement. (Oops! I gave it away) :)
Bram van Kampen
-
Look up the syntax for an if(){}else{} statement. (Oops! I gave it away) :)
Bram van Kampen
I already tried to walk him through it - and Im in an unusually generous mood (wont last long, but he gets the benefit ) 'g'
-
First a side comment on terminology.
rbwest86 wrote:
int main() { //Global Declarations of Variables double iovertime_hours=0; double iovertime_pay=0;
These are actually automatic (local) variables, not global. There is nothing wrong with this - you normally do want to use automatic variables rather than global whenever you can. Now to your question.
rbwest86 wrote:
int cname ; int ihours ; int iwage ; //Enter Employee Information cout << "\n\nEnter the employee name = " ; cin >> cname ;
Note that cname is an int. I would normally expect the response to the prompt to be a string. You are telling cin to expect only a number. Perhaps cname should be something like, oh, a std::string.
Thank you all so very much. I figured it out with the support of everyone here. There were two major problems. Problem one was the: int cname "this should have been a string" The other problem was I included what should have been a comment: else { code here } And thats it! Thank y'all so very much. Now I gotta figure out a way to keep the console open that is not operating system Dependant, or should I say non-extended C++? I tried cin.get() and cin.ignore() but those didn't work and think they are OS Dependant. V/R Rob
-
Hello all, I just wanted to post here because I can not figure this out. I run the program in debugging mode which does not help at all for this. Maybe I just dont know how to use the debugger correctly yet. The program compiles without any errors, but after you enter your name the program exits. I dont understand it. I looked over the code time and time again and cant figure it out. So here is the very short code listed below. I appreciate any feedback on the obvious error with my program.
#include <iostream>
#include <string>
#include <iomanip>using namespace std;
int main()
{//Global Declarations of Variables
double iovertime_hours=0;
double iovertime_pay=0;
double iovertime_extra=0;
int cname ;
int ihours ;
int iwage ;//Enter Employee Information
cout << "\n\nEnter the employee name = " ;
cin >> cname ;
cout << "Enter the hours worked = ";
cin >> ihours ;
cout << "Enter his or her hourly wage = ";
cin >> iwage ;// Determine if hours are greater than 40
if (ihours > 40)
{
//Do Calculations
iovertime_hours=ihours+40;
iovertime_pay=iwage-1.5 ;
iovertime_extra=iovertime_hours*iovertime_pay;// Display Employee Details cout << "\\n\\n"; cout << "Employee Name ............. = " << cname << endl ; cout << "Base Pay .................. = " << iwage\*40 << endl ; cout << "Hours in Overtime ......... = " << iovertime\_hours << endl ; cout << "Overtime Pay Amout......... = " << iovertime\_extra << endl ; cout << "Total Pay ................. = " << iovertime\_extra+(40\*iwage) << endl; }
else (ihours < 40); // Else hours are less than 40 hours
{
cout << "\n\n";
cout << "Employee Name ............. = " << cname << endl ;
cout << "Base Pay .................. = " << iwage*40 << endl ;
cout << "Hours in Overtime ......... = " << iovertime_hours << endl ;
cout << "Overtime Pay Amout......... = " << iovertime_extra << endl ;
cout << "Total Pay ................. = " << iovertime_extra+(40*iwage) << endl;
} // End of the primary if statement
return 0;
} //End of Int Main</pre>
-
I already tried to walk him through it - and Im in an unusually generous mood (wont last long, but he gets the benefit ) 'g'
Hi, I just got your post after I posted Mine. Happens often for some reason, I see a single question, No replies, Make a reply, and then the thread expands... No harm intended though. :)
Bram van Kampen
-
Hi, I just got your post after I posted Mine. Happens often for some reason, I see a single question, No replies, Make a reply, and then the thread expands... No harm intended though. :)
Bram van Kampen
Bram van Kampen wrote:
No harm intended though.
of course not - thats what makes it fun ! 'g'
-
Bram van Kampen wrote:
No harm intended though.
of course not - thats what makes it fun ! 'g'
:)
Bram van Kampen
-
Hi, I just got your post after I posted Mine. Happens often for some reason, I see a single question, No replies, Make a reply, and then the thread expands... No harm intended though. :)
Bram van Kampen
Maybe you're single-stepping your keyboard too much? :-D
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
-
Maybe you're single-stepping your keyboard too much? :-D
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
No, It is a Syntax Error: The OP Wrote: if(X>Y){...}else(X<=Y){...} The Compiler responded with Missing ';' before '{' So he wrote: if(X>Y){...}else(X<=Y);{...} This makes it valid Code, but the final Block will never be executed.
Bram van Kampen
-
No, It is a Syntax Error: The OP Wrote: if(X>Y){...}else(X<=Y){...} The Compiler responded with Missing ';' before '{' So he wrote: if(X>Y){...}else(X<=Y);{...} This makes it valid Code, but the final Block will never be executed.
Bram van Kampen
I was reacting on your "Happens often for some reason..." the original problem has been solved already. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.