boiling point of substance ERROR

Im not sure whats wrong with this.It is to ask for the substance bioling piont and tell what it is. Its not compiling. Any ideas?

#include <cstdlib>
#include <iostream>

using namespace std;
int main()
{

int withinXpercent(double ref,double data,double x) ;
double ref;
double data;
double x = .05;
{
cout<<"Enter the boiling point of the substance: "<<endl;

cout<<"% if",&data;

if (withinXpercent(100,data,x))
cout<<"Your substance is Water."<<endl;

else if ( withinXpercent(357,data,x))
cout<<"Your substance is Mercury."<<endl;

else if ( withinXpercent(1187,data,x))
cout<<"Your substance is Copper."<<endl;

else if ( withinXpercent(2193,data,x))
cout<<"Your substance is Silver."<<endl;

else if ( withinXpercent(2660,data,x))
cout<<"Your substance is Gold."<<endl;

else
cout<<"Substance Unknown."<<endl;

return 0;
}
int withinXpercent(double ref,double data,double x);
{
if (( ref - x * ref) <= data <= (ref + x * ref))
return 1;
else
return 0;
}

Remove the opening brace after double x = .05;
I did that and now its crashing(compiling quickly and disappears)
Are you sure it is crashing? Or is it just closing after it has finished running the program?

http://www.cplusplus.com/forum/beginner/1988/
It closes after running.
Do you know why?
So i went through the link you posted and I used what they suggested and I dont know if im putting something wrong but does not work. This is the program so far:

#include <cstdlib>
#include <iostream>
#include <ctime>
using namespace std;
int main()
{

int withinXpercent(double ref,double data,double x);
double ref;
double data;
double x = .05;

cout<<"Enter the boiling point of the substance: "<<endl;

cout<<"% if",&data;

if (withinXpercent(100,data,x))
cout<<"Your substance is Water."<<endl;

else if ( withinXpercent(357,data,x))
cout<<"Your substance is Mercury."<<endl;

else if ( withinXpercent(1187,data,x))
cout<<"Your substance is Copper."<<endl;

else if ( withinXpercent(2193,data,x))
cout<<"Your substance is Silver."<<endl;

else if ( withinXpercent(2660,data,x))
cout<<"Your substance is Gold."<<endl;

else
cout<<"Substance Unknown."<<endl;

return 0;
}
int withinXpercent(double ref,double data,double x)
{
if (( ref - x * ref) <= data <= (ref + x * ref))
return 1;
else

return 0;
cin.get();


}
Did you read the second post? The one by Duoas? That's the important one. And you need to do it before the return 0 in main.
Topic archived. No new replies allowed.