Feb 21, 2013 at 8:33pm UTC
Does any one know why this is not compiling?
#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;
}
Feb 21, 2013 at 8:38pm UTC
Found a problem, your cout<<"% if" ,&data;
is not the C++ format. That is C. You want the cin>>&data;
function.
Also, unless you put a cin.get()
at the end, your console window will close down without giving you time to read your final output.
Hope this helps.
Last edited on Feb 21, 2013 at 8:39pm UTC
Feb 21, 2013 at 8:46pm UTC
Wow that help, it now compiles thanks, but it disappears after typing the boiling point. That is,I think there should be something that makes the program stay open to show the results. Do you know what that is?
Feb 21, 2013 at 11:13pm UTC
a number of things. starting from worst to best...
system("pause") //on windows only
int c = getchar()
cin.get();
cin>> variable
getline(stream, std::string)
noecho(); getch() //linux only unless you have cygwin on windows
Feb 24, 2013 at 6:27am UTC
system("pause") //on windows only
int c = getchar()
cin.get();
cin>> variable