need assistance figuring out the why my output is wrong....

ok, first off im very new to c++. this is only my second actual program ive writen. this is not all of it, but the beginings. im trying to build a bit of it at a time and then add to it as it is all running right.

thus far my problem is this. when i run it, i enter option 2 (you will see in my program below), and then enter the info, and then it factors the grosspay variable. the problem is, is that its not figuring my equation and is simply giving me a 0 as the amount of pay, which is obviously wrong.

ill list it below. im not getting any errors to compile but its not figuring.
any help is greatly appreciated.

// Project 2.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{

float reghours=0, overtime=0, overtimepay =0;
int commision=0, pieces=0, n, grosspay, hourlywage=0 ;
n = 1,2,3,4;
enum Etype {Manager, Hourly, Commision, Piece};

overtimepay = overtime * (1.5 * hourlywage);
grosspay = (reghours * hourlywage) + overtimepay;

cout<<" Please enter the approprate employee code to be figure. Enter 1 for Managers, 2 for Hourly workers, 3 for Commissioned workers, and 4 for Piece workers: ";
cin>> n;

switch (n) {
case 1:
cout<< "The Manager will receive 1000 dollars for the week.";
break;
case 2:
cout<< "Please enter the number of hours worked between 1 and 40: ";
cin>>reghours;

cout<< "Please enter the number of hours worked over 40: ";
cin>>overtime;

cout<< "Please enter the hourly rate pay to this employee: ";
cin>>hourlywage;

cout<< "This employees pay for the week is: " << grosspay << endl;
break;
}

}
Thats becouse you calculate grosspay and overtimepay before user inputs anyting.
Just move lines 14 and 15 before line 35.
And use code tags next time.
thanks so much hamster, that fixed it. a question though, and again im very new so i appologize, but what do you mean by "use code tags".

Hi there Blue! I think I see your issue here. It seems you are assigning a value to the overtime and grosspay variables right after you just assigned a 0 value to the variables used in the formulas that figure those 2 variables. So you effectively make grosspay and overtimepay equal to 0 from the start and any reference to them thereafter will be, of course, 0.

If you wish to reference back to a formula to figure a value based on user input you should look into functions: http://www.cplusplus.com/doc/tutorial/functions/

Otherwise, as a suggestion, I would simply remove the overtimepay and grosspay lines altogether and replace them in the switch statement with the formulas themselves so that it will do the arithmetic inline.

I'll let more learned persons talk to you about the usage of the comma operator ala n=1,2,3,4.

Hope this helped.
When posting code, click the '#' on the right hand side under 'Format' and insert your code between the tags.

You are going to run in to more problems when calculating your grosspay later because you are using cin, which leaves whitespace/new line's in the stream after extraction.

Read this:
http://cplusplus.com/forum/articles/6046/
Topic archived. No new replies allowed.