// RealScenarioOFF.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
#include <math.h>
usingnamespace std;
int main()
{
int totalall=0, totalexp=0;
float numberofemp, milesrate=0.50, counter, milestraveled, enginesize, avg, rate50, rate80;
string claim_month,help;
char empname[20], departname[20];
cout<<"Welcome to My Mileage Cost Calculation."<<endl;
cout<<"Do you require help using this program? Y for YES and N for NO."<<endl;
cin>>help;
if (help=="Y"||help=="y")
{
cout<<"\n SELECTED HELP \n"<<endl;
cout<<"\nFirst Enter the number of Employees follwed by Name, Claim Month and the Mileage Traveled."<<endl;
cout<<"Then Enter your Engine size according to number."<<endl;
cout<<"At the end there will be summery of your costs."<<endl;
}
else (help=="N"||help=="n"); // The statement for else
{
cout<<"\nEnjoy the program"<<endl;
}
do //Do loop it will repeat the looper from here
{
cout<<"Please enter Employees ( Max 20 )"<<endl;
cin>>numberofemp;
}while(numberofemp>20);
for(counter=0;counter<numberofemp;counter++)
{
cout<<"\nEnter Your name:"<<endl;
cin>>empname;
cout<<"Please Enter Claim Month (MM/YYYY)"<<endl;
cin>>claim_month;
cout<<"Enter The Department Name: "<<endl;
cin>>departname;
cout<<"Please enter the Mileage Traveled with car"<<endl;
cin>>milestraveled;
cout<<"Enter you Engine Size according to number()This Also shows the Rate"<<endl;
cout<<"Diesel 1 -Rate- Full expenses Rate"<<endl;
cout<<"Under 1400cc 2 -Rate- 80% Of Full Rate"<<endl;
cout<<"1400cc and Above 3 -Rate- 50% Of Full Rate"<<endl;
cin>>enginesize;
cout<<"************************************************************************"<<endl;
cout<<"|\t\t\t The Company Finance Department"<<endl;
cout<<"|Employee Name:"<<empname<<endl;
cout<<"|Department Name:"<<departname<<endl;
cout<<"|Clam Month:"<<claim_month<<endl;
cout<<"|Engine Size Number: ("<<enginesize<<")\t Rate:";
// *********************************************************************************************8
if(enginesize== 1)
{
cout<<"Full Expences Rate"<<endl;
}
// *********************************************************************************************8
if( enginesize == 2)
{
cout<<"80% Of Full Rate"<<endl;
}
// *********************************************************************************************8
if (enginesize ==3)
{
cout<<"50% Of Full Rate"<<endl;
}
// **************************************************************************************************************************************************************8
cout<<"|Monthly Travel Expenses:\t(GBP)"<<totalexp<<endl;
if(enginesize== 1)
{
cout<<"Full Expences Rate"<<totalexp;
}
if (milestraveled <=500)
{
totalexp = milesrate*milestraveled;
}
else
{
totalexp = milesrate*(500) + (milesrate/2) *(milestraveled - 500);
}
// *********************************************************************************************8
if( enginesize == 2)
{
totalexp = milestraveled*0.5/80*100; //HELP HERE
}
// *********************************************************************************************8
if (enginesize ==3)
{
cout<<"50% Of Full Rate"<<endl;
}
if (milestraveled <=500)
{
totalexp = milesrate*milestraveled/50*100;
}
cout<<"\n************************************************************************"<<endl;
totalall = totalall+milestraveled*50;
avg = totalall/numberofemp;
}
cout<<"***********************************Summary*******************************"<<endl;
cout<<"\n|Department:"<<departname;
cout<<"\n|Month: 05/2014";
cout<<"\n|Number of Staff:"<<numberofemp;
cout<<"\n|Department Total Expenses:\t (GBP)"<<totalall;
cout<<"\n|Average Expenses: \t (GBP)"<<avg;
cout<<"\n************************************************************************"<<endl;
system("pause");
return 0;
}
When showing the first employee statement. it calculate 80% of milestravel x 50
inside the if statement. Help?
You output totalexp on line 89 before you actually calculate it later in the program.
Edit: You don't need to calculate the average on line 120 each time you go through the for loop, that can go outside. I might make sure they can't enter 0 for numberofemp.
I might see if you can consolidate some of the code instead of checking the engine types with if statements twice.