Problem in a program

Hello,
I am trying to make a program , i had some trouble but I have made one with the help of the tutorial here.But it is still not working ,Can anyone please tell me what is the problem with this program ,I will apreciate .

#include<iostream>
using namespace std;
void MilesperGal(int FuelUsed,int mileage)
{
cout << "enter the fuel used";
cin>>FuelUsed;
cout<<"enter mileage ";
cin>>mileage;
int MilesPerGal;


MilesPerGal = mileage/FuelUsed;
cout<<MilesPerGal;
}
void mileage(int FuelUsed,int MilesPerGal)
{
cout << "enter the fuel used";
cin>>FuelUsed;
cout<<"enter MPG ";
cin>>MilesPerGal;
int Mileage;

Mileage=FuelUsed*MilesPerGal;

cout<<Mileage;
}
void fuelUsed (int MilesPerGal,int Mileage)
{
cout << "enter the Mileage used";
cin>>Mileage;
cout<<"enter mileage ";
cin>>MilesPerGal;
int FuelUsed;


FuelUsed=Mileage/MilesPerGal;


cout<<FuelUsed;




int main()
{
char 'x','m','d','g','q';

cout<<"Enter M to caluculate mileage , D for distance traveled ,G for Gal per miles and Q to quit the program";
cin>>

if (x == 'm')
{
void MilesperGal(int FuelUsed,int mileage);
}
else if (x == 'd') {
void mileage(int FuelUsed,int MilesPerGal);
}
else if(x=='g')
{
void fuelUsed (int MilesPerGal,int Mileage)'
}
else
return 0;
}
Last edited on
I copied your code to be able to name the lines:
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
#include<iostream>
using namespace std;
void MilesperGal(int FuelUsed,int mileage)
{
cout << "enter the fuel used";
cin>>FuelUsed;
cout<<"enter mileage ";
cin>>mileage;
int MilesPerGal;


MilesPerGal = mileage/FuelUsed;
cout<<MilesPerGal;
}
void mileage(int FuelUsed,int MilesPerGal)
{
cout << "enter the fuel used";
cin>>FuelUsed;
cout<<"enter MPG ";
cin>>MilesPerGal;
int Mileage;

Mileage=FuelUsed*MilesPerGal;

cout<<Mileage;
}
void fuelUsed (int MilesPerGal,int Mileage)
{
cout << "enter the Mileage used";
cin>>Mileage;
cout<<"enter mileage ";
cin>>MilesPerGal;
int FuelUsed;


FuelUsed=Mileage/MilesPerGal;


cout<<FuelUsed;




int main()
{
char 'x','m','d','g','q';

cout<<"Enter M to caluculate mileage , D for distance traveled ,G for Gal per miles and Q to quit the program";
cin>>

if (x == 'm')
{
void MilesperGal(int FuelUsed,int mileage);
}
else if (x == 'd') {
void mileage(int FuelUsed,int MilesPerGal);
}
else if(x=='g')
{
void fuelUsed (int MilesPerGal,int Mileage)'
}
else
return 0;
} 


You made several mistakes:
* Your functions take arguments but they are not needed => make them local variables
* You missed a { after line 39
* line 46 must be altered to declare a variable x (without "" or '')
* this variable x has to be added in line 49
* on lines 53, 56, 60 you declare functions! You don't call them.
* a chained if - else should be replaced by a switch-case - it's much clearer

fixed code:

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
#include<iostream>
using namespace std;
void MilesperGal()
{
	int FuelUsed, mileage ;
	cout << "enter the fuel used";
	cin>>FuelUsed;
	cout<<"enter mileage ";
	cin>>mileage;
	int MilesPerGal;

	MilesPerGal = mileage/FuelUsed;
	cout<<MilesPerGal;
}
void mileage()
{
	int FuelUsed, MilesPerGal;
	cout << "enter the fuel used";
	cin>>FuelUsed;
	cout<<"enter MPG ";
	cin>>MilesPerGal;
	int Mileage;

	Mileage=FuelUsed*MilesPerGal;

	cout<<Mileage;
}
void fuelUsed ()
{
	int MilesPerGal, Mileage;
	cout << "enter the Mileage used";
	cin>>Mileage;
	cout<<"enter mileage ";
	cin>>MilesPerGal;
	int FuelUsed;


	FuelUsed=Mileage/MilesPerGal;


	cout<<FuelUsed;
} // missed this




int main()
{
	char x ; // only define the variables not the options!

	cout<<"Enter M to caluculate mileage , D for distance traveled ,G for Gal per miles and Q to quit the program ";
	cin>>x ; 

	cout << x << endl ;

	switch (x)
	{
	case 'm':
	case 'M':
		MilesperGal();
		break ;
	case 'd':
	case 'D':
		mileage();
		break ;
	case 'g':
	case 'G':
		fuelUsed ();
		break;
	default:
		return 1; // since it is an error to type in the wrong letter
	}
}
Topic archived. No new replies allowed.