# My first C++ project



## OnlyGirlInClass (Oct 3, 2008)

Hi I need some help with my project, Ive been trying everything I know to make it work but it wont.

My project is to make a program that converts Celsius to Fahrenheit or Fahrenheit to Celsius or just exit. 

Here's my program:

#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{

//Declarating Variables

double celsius;
int option = 0;
double fahrenheit;


//Promt user for options

cout<<"Please pick one of the following options:"<<endl;
cout<<"1- Convert from Celsius to Fahrenheit."<<endl;
cout<<"2- Convert from Fahrenheit to Celsius."<<endl;
cout<<"3- Exit program!"<<endl;
cin>>option;


//Calculating Temperature

if (option == 1)
{
cout<<"Please enter Celsius temperature: "<<endl;
cin>>celsius;
fahrenheit = (celsius * 1.8 + 32);
cout<<" Your result is: "<<fahrenheit<<"degrees in Fahrenheit. "<<endl;
}
else if (option == 2)
{
cout<<"Please enter Fahrenheit temperature: ";
cin>>fahrenheit;
celsius = 5.0/9.0*(fahrenheit - 32) ;
cout<<" Your result is: "<<celsius<<"degrees in Celsius. "<<endl;
}
else (option == 3)
{
cout<<"Bye Bye!"<<endl;
}

return 0;

}

Um ok, so it compiles and everything but when I execute it it gets as far as asking the user to enter the temperature and then when I press enter it closes. :4-dontkno 

Sooo :1angel: I was wondering if anyone had an idea how to fix it...


Thanks in advance :heartlove
(I am working on Dev-C++.)


----------



## ScottG489 (Aug 9, 2008)

If you have an else statement that means its going to run if none of the other if, or else if conditions are true. The else statement never takes a condition since it runs based on the fact that none of the other conditions were true.

Btw, what compiler or IDE are you using for C++? Usually it will tell you where the error is and the problem is either on that line or the line before it for most compiler errors.


----------



## OnlyGirlInClass (Oct 3, 2008)

I see what you mean, i erased that if under the else, i tried running it again but it still closes after i input a temperature.. 

and for the compiler im using i think its GNU, im using dev-C++ from bloodshed.net im supposed to be using Borland C++ , im currently looking for it.

btw, thank you


----------



## ScottG489 (Aug 9, 2008)

Thats weird. I compiled it in Dev-C++ and it gave me errors and didn't run.

And what do you mean you erased an if. You should have added one....

btw add system("PAUSE"); above return 0; at the end. I think thats why your program doesn't stop. I don't even see how it compiled in the first place though.


----------



## OnlyGirlInClass (Oct 3, 2008)

Oh sorry I understood wrong, I added the else at the end with no conditions and aslo added the system(''PAUSE"); that was my bad I forgot about it 

Here is my program again:

#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{

//Declarating Variables

double celsius;
int option = 0;
double fahrenheit;


//Promt user for options

cout<<"Please pick one of the following options:"<<endl;
cout<<"1- Convert from Celsius to Fahrenheit."<<endl;
cout<<"2- Convert from Fahrenheit to Celsius."<<endl;
cout<<"3- Exit program!"<<endl;
cin>>option;


//Calculating Temperature

if (option == 1)
{
cout<<"Please enter Celsius temperature: "<<endl;
cin>>celsius;
fahrenheit = (celsius * 1.8 + 32);
cout<<" Your result is: "<<fahrenheit<<"degrees in Fahrenheit. "<<endl;
}
else if (option == 2)
{
cout<<"Please enter Fahrenheit temperature: ";
cin>>fahrenheit;
celsius = 5.0/9.0*(fahrenheit - 32) ;
cout<<" Your result is: "<<celsius<<"degrees in Celsius. "<<endl;
}
else if (option == 3)
{
cout<<"Bye Bye!"<<endl;
}
else

system("PAUSE");
return 0;


}

I apologize for my error im just starting to use C++


----------



## OnlyGirlInClass (Oct 3, 2008)

Its working fine now I added an cin>> at the end so it would stay open to see what would happens and it executes fine , YAY

anyways; Thanks a lot for your help, a lot a lot


----------

