I am trying to make an employee discount program that reads employee number and discount from an input file. I need it to display an error message when a character is put into the variable. I can't seem to figure this out. I'm a newbie so I don't know that many identifiers yet. This compiles with an unexpected output. I'm not sure how to get the variables for all three employees as well. Any help is greatly appreciated.
/* Program name: main.cpp
* Author: Carl Snyder
* Date last updated: 09/11/2022
* Purpose: Top employee discount calculator
*/
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
int main()
{
ifstream inFile;
int winning_Num;
int employee_Num;
double total_Bill;
double discount_Percent;
double discount_Amount;
double bill_After_Discount;
inFile.open("EOM.txt");
inFile >> winning_Num >> discount_Percent;
cout << "Enter your employee number to see if you get a discount: ";
cin >> employee_Num;
cout << fixed << showpoint << setprecision(2);
if (employee_Num >= 10000 && employee_Num <= 99999)
{
if (employee_Num == winning_Num)
{
cout << "You have won a discount of " << discount_Percent << "%." << endl;
cout << "Enter the total bill: " << endl;
cin >> total_Bill;
if (total_Bill > 0)
{
discount_Amount = total_Bill * discount_Percent;
bill_After_Discount = total_Bill - discount_Amount;
cout << "Your discount will take $" << discount_Amount << " off your bill. "
<< endl;
cout << "Your new total is $" << bill_After_Discount << "." << endl;
return 0;
}
if (total_Bill <= 0)
{
cout << "The total should be greater than 0. The program will now
exit.";
}
else
cout << "You entered something that is not a number! The program will
now exit.";
}
else
cout << "Sorry you did not win a discount this month. Try again next
month.";
}
if (employee_Num <=9999 || employee_Num >=100000)
{
cout << "You entered a number that is out of range! Employee numbers are 5
digits (between 10000 and 99999). Program will now exit.";
}
else
cout << "You did not enter a number! The program will now exit.";
return 0;
}