sugestetion welcome

//this program is ment to convert distances fro metric to sae. it compiles down to the last } then gives me an errror code saying that } expected at end of input where is it missing?//
//,//
//begins main function//

#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;

int main()
{
double distance;
double kilometers;
double miles;
double answer;
const double a = 0.62137119;
const double b = 1.609344;
double yards;
double meters;
const double c = 0.9144;
const double d = 1.0936133;
bool y;
y = true;
bool n;
n= false;
{
cout << " name distance; kilometers, miles, yards, or meters"<< endl;
{
if (distance == kilometers)
cout <<boolalpha<< y<<" you entered kilometers y/n? "<<answer<<endl;
cin >>boolalpha>> y >> y;
if (answer = y)
{
while (kilometers != -1)
cin >> kilometers;
miles = kilometers * a;
cout << "miles = " <<miles<<endl;
}
cin >>boolalpha>> n >> n;
if (answer != y)
{
cout << " name distance; kilometers, miles, yards, or meters"<< endl;

system("PAUSE");
return EXIT_SUCCESS;
}
else if (distance == miles)
cout <<boolalpha<< y<< " you entered miles y/n" <<answer<<endl;
cin >>boolalpha>> y;
if (answer == y)
{
while (miles !=-1)
cin >> miles;
kilometers = miles * b;
cout << " kilomters = " <<kilometers<<endl;;
}
cin >>boolalpha>> n >> n;
if (answer != y)
{
cout << " name distance; kilometers, miles, yards, or meters"<< endl;

system("PAUSE");
return EXIT_SUCCESS;
}
else if(distance == yards)
cout <<boolalpha<< y << " you entered yards y/n ?" <<answer<<endl;
cin >>boolalpha>> y >> y;
if (answer == y)
{
while (yards != -1)
cin >> yards;
yards = meters * c;
cout << " yards = " <<yards<<endl;
}
cin >>boolalpha>> n>> n;
if (answer != y)
{
cout << " name distance; kilometers, miles, yards, or meters" << endl;

system("PAUSE");
return EXIT_SUCCESS;
}
else if (distance == meters)
cout <<boolalpha<< y << " you entered meters y/n?" <<answer<<endl;
cin >>boolalpha>> y >> y;
if (answer == y)
{
while (meters != -1)
cin >> meters;
meters = yards * d;
cout << " meters = " <<meters<<endl;
}
cin >>boolalpha>> n>> n;
if (answer != y)
{
cout << " name distance; kilometers, miles, yards, or meters" << endl;

system("PAUSE");
return EXIT_SUCCESS;
}


system("PAUSE");
return EXIT_SUCCESS;
}

}
Last edited on
I suggest you use code tags:

[code]
put your code here
[/code]
A question would be nice as well. An explanation of what's expected from your program and where it deviates from this expectation would also be welcome.
I see a few thing wrong with these 5 lines near the beginning of main

1
2
3
4
5
if (distance = kilometers) /*3 thing wrong here: where is this distance variable declared, what does kilometers equal, and lastly = is not a comparasion, i think you should use ==*/
cout <<" you entered kilometers y/n? "<<answer<<endl; //where is answer declared?
cin >> y;
if (answer = y)/* again, == not =, and you can not compare a non-existant variable to somthing*/
{



im not gonna question the program logic...
the program is meant to calculate distances fro metric to sae and from sae to metric, with the code tags would i place thouse between my if statements and cin statments for each form of mesurements.
@ dong shi
i was wanting to use a bool statement for the question of "did you enter 'such' distance y/n?" but i couldnt get the ones i tryed to work, any sugestions would grately help ty
Last edited on
found it at the very end
so, it works properly now?
sqoobie wrote:
with the code tags would i place thouse between my if statements and cin statments for each form of mesurements

No. [code] tags are for forum posts. You put them around your whole code like so:
[code]
int main()
{
return 0;
}
[/code]
which becomes:
1
2
3
4
int main()
{
   return 0;
}
Topic archived. No new replies allowed.