![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Programming A discussion forum for programs and programming used in tech-related businesses. |
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) |
|
Registered User
Join Date: Oct 2008
Location: Puerto Rico
Posts: 4
OS: XP
|
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. Sooo I was wondering if anyone had an idea how to fix it...Thanks in advance ![]() (I am working on Dev-C++.) |
|
|
|
| Important Information |
|
Join the #1 Tech Support Forum Today - It's Totally Free!
TechSupportForum.com is a leading support website for your computer needs. We offer free, friendly and personalized computer support. Why pay to have your computer fixed when you can do it for free. Join TechSupportforum.com Today - Click Here |
|
|
#2 (permalink) |
|
Registered User
|
Re: My first C++ project
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. Last edited by ScottG489; 10-03-2008 at 12:39 PM. |
|
|
|
|
|
#3 (permalink) |
|
Registered User
Join Date: Oct 2008
Location: Puerto Rico
Posts: 4
OS: XP
|
Re: My first C++ project
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 :)
__________________
Student. |
|
|
|
|
|
#4 (permalink) |
|
Registered User
|
Re: My first C++ project
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. |
|
|
|
|
|
#5 (permalink) |
|
Registered User
Join Date: Oct 2008
Location: Puerto Rico
Posts: 4
OS: XP
|
Re: My first C++ project
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++ :)
__________________
Student. |
|
|
|
|
|
#6 (permalink) |
|
Registered User
Join Date: Oct 2008
Location: Puerto Rico
Posts: 4
OS: XP
|
Re: My first C++ project
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
__________________
Student. |
|
|
|
![]() |
| Thread Tools | |
|
|