What is wrong?!?! HELP PLEASE!

I am trying to write a code with a switch function. I got it working, but not correctly. I don't know what I am doing wrong. Please help!

The code doesn't work for other paycodes than hourly. when you run it, the if statement doesn't work right, and I don't know


// Ask a user for a name and pay type, then set paycode based on user input. Then ask user for input in order to find their overall pay.

#include <string>
#include <iostream>
using namespace std;

int main()
{

// declare variables
char paycode;
double rate = 0.0, hours = 0.0 , pieces = 0.0, comm = 0.0, sales = 0.0, salary = 0.0, paynum, pay = 0.0;
string name;

// display "menu" for selection

cout << "Enter Name: ";
cin >> name;

cout << "Enter the PayCode type as one of the following: -\n";
cout << " H - Hourly\n";
cout << " P - Piece Work\n";
cout << " C - Commission\n";
cout << " S - Salary\n";
cout << "Enter your choice :";
cin >> paycode;

// select case of value entered
switch (paycode)
{
case 'H':
case 'h':
paynum = 1 ;
break;
case 'P':
case 'p':
paynum = 2;
break;
case 'C':
case 'c':
paynum = 3;
break;
case 'S':
case 's':
paynum = 4;
break;
default:
cout << "Please enter a valid selection." << endl;
return paynum;
}
// end of switch structure
// start of finding amount of pay for the person and entering values
if (paynum = 1)
{
cout << "Please enter the rate:";
cin >> rate;
cout << "Please enter the hours worked:";
cin >> hours;
pay = rate * hours;

}
else
{
if (paynum = 2)
{
cout << "Please enter the rate:";
cin >> rate;
cout << "Please enter the number of pieces:";
cin >> pieces;
pay = rate * pieces;

}
else
{
if (paynum = 3)
{
cout << "Please enter the amount of commission:";
cin >> comm;
cout << "Please enter the number of sales:";
cin >> sales;
pay = comm * sales;

}
else
{
if (paynum = 4)
{
cout << "Please enter the salary:";
cin >> salary;
pay = salary;
}
else
{
cout << "Please enter a valid selection." ;
}
}

}
}

cout << endl << "The amount of pay for " << name << " is " << pay << endl;

system ("pause");
}

// output the value determineed in the switch/case
Instead of the assignment operator ( = ) as in the code

if (paynum = 1)


you shall use the comparision operator ( == )
Thank you.
Topic archived. No new replies allowed.