Help C++ if problem

Im doing an IT course and this my first programming scenario (UK)

- Every Mile is 50p
- Engine size and rate percentage taken away from total expences
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// RealScenarioOFF.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include <math.h>

using namespace 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?

This is the section im testing out
1
2
3
4
5
6
 // *********************************************************************************************8
 if( enginesize == 2) 
 {
   totalexp = milestraveled*0.5/80*100;
}
  // *********************************************************************************************8 
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.
Last edited on
line 29
 
else (help=="N"||help=="n");
should not end with a semicolon.
it should have the keyword if in there:
 
else if (help=="N"||help=="n")

Last edited on
Topic archived. No new replies allowed.