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:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* 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
Go Back   Tech Support Forum > The IT Pro > Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read


Programming A discussion forum for programs and programming used in tech-related businesses.

Reply
 
LinkBack Thread Tools
Old 10-03-2008, 11:32 AM   #1 (permalink)
Registered User
 
Join Date: Oct 2008
Location: Puerto Rico
Posts: 4
OS: XP


Pencil My first C++ project

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++.)
OnlyGirlInClass is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
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

Old 10-03-2008, 12:37 PM   #2 (permalink)
Registered User
 
Join Date: Aug 2008
Location: New York State
Posts: 50
OS: XP Pro SP 3


Send a message via AIM to ScottG489
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.
ScottG489 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 10-03-2008, 01:06 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.
OnlyGirlInClass is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 10-03-2008, 01:12 PM   #4 (permalink)
Registered User
 
Join Date: Aug 2008
Location: New York State
Posts: 50
OS: XP Pro SP 3


Send a message via AIM to ScottG489
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.
ScottG489 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 10-03-2008, 01:24 PM   #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.
OnlyGirlInClass is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Old 10-03-2008, 01:32 PM   #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.
OnlyGirlInClass is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -7. The time now is 06:20 AM.



Copyright 2001 - 2009, Tech Support Forum
Home Tips Plus | Outdoor Basecamp | Automotive Support Forum

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85