The beginning of my code executes fine, but problems occur when I try to receive user input for paycode. When debugging it doesn't allow me to enter a value. Any help or advice on how to fix this code would be much appreciated.
(Sorry if my logic doesn't make any sense!)
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
cout<<"Please enter your employee name or type 'exit' to end the program." << endl;
std::getline(std::cin, employeename);
if (employeename == "exit")
{
return 0;
}
cout << "Please enter your employee id." << endl;
cin.get(employeeid, 20);
cin.ignore(80, '\n');
cout<<"Please enter your hours worked." << endl;
cin >> hoursworked;
while (cin.fail())
{
cin.clear();
cin.ignore(999, '\n');
cout << "That was not a vaild responce. Please enter another value." << endl;
cin >> hoursworked;
}
cout<<"Please enter your paycode." << endl;
cin.get(paycode, 20);
cin.ignore(80, '\n');
while ((paycode[20] != 'M') && (paycode[20] != 'C') && (paycode[20] != 'L'))
{
cin.clear();
cin.ignore(999, '\n');
cout << "Valid responces are M C L" << endl;
cin.get(paycode, 20);
cin.ignore(80, '\n');
}
cout<<"Please enter your insurance code." << endl;
cin.get(insurancecode, 20);
cin.ignore(80, '\n');
while ((insurancecode[20] != 'A') && (insurancecode[20] != 'B') && (insurancecode[20] != 'C'))
{
cin.clear();
cin.ignore(999, '\n');
cout << "Valid responces are A B C." << endl;
}
switch (paycode[20])
{
case 'M':
hourlypay = 27.50; break;
case 'C':
hourlypay = 19.50; break;
case 'L':
hourlypay = 10.35; break;
}
switch (insurancecode[20])
{
case 'A':
insurancetax = 25.00; break;
case 'B':
insurancetax = 15.00; break;
case 'C':
insurancetax = 0.00; break;
}