+ 2

Why is this code not compiling?

Hi Guys, This is my first piece of code and for some reason i cannot get it to compile, can some one please look into this and let me know whats wrong with it? Thanks in Advance #include <string> #include <iostream> #include <iomanip> using namespace std; int main() { string Name; string NationalInsurenceNumber; string RateOfPay; string TotalHoursWorked; float HoursWorked; const float BasicHours = 35; float PayRate; int BasicHours = 35; int BasicPay = BasicHours * PayRate; int OvertimeHours = TotalHoursWorked - BasicHours; int OvertimePay = PayRate * 1.5 * OvertimeHours; int GrossPay = BasicPay + OvertimePay; cout << "Welcome! Please Fill In the Following Details." << endl; cout << "Name:"; cin >> setw(20) >> Name; cout << "NationalInsurenceNumber:" << endl; cin >> setw(12) >> NationalInsurenceNumber; cout << "PayRate:" << endl; cin >> PayRate; cout << "TotalHoursWorked:" << endl; cin >> HoursWorked; if (HoursWorked > 35) { float OverTime1 = HoursWorked - BasicHours; cout << "OverTimeAmount:" << OverTime1 << endl; float multi = OverTime1 + BasicHours; cout << "HoursDone:" << multi << endl; float GrossPay = PayRate*multi; cout << "GrossPayIs:" << GrossPay << endl; system("pause"); } if (HoursWorked > 35) { cout << "HoursWorked:" << HoursWorked << endl; float GrossPay1 = PayRate*HoursWorked; cout << "GrossAmount:" << GrossPay1 << endl; system("pause"); } return 0; }

11th Dec 2016, 12:58 AM
Arjun Shanmuganathan
Arjun Shanmuganathan - avatar
1 Answer
+ 2
PayRate is undefined when you multiply for BasicPay. Same with HoursWorked. Maybe you want to ask for them first, and then use those values for the operation.
11th Dec 2016, 1:08 AM
Nahuel
Nahuel - avatar