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;
#include<iostream>
usingnamespace 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);
}
elseif (x == 'd') {
void mileage(int FuelUsed,int MilesPerGal);
}
elseif(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
#include<iostream>
usingnamespace 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
}
}