Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,208 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,322 people online right now. Registration is fast and FREE... Join Now!




fahrenheit to celsius

 
Reply to this topicStart new topic

fahrenheit to celsius, Online class

debeth
7 Jul, 2008 - 01:01 PM
Post #1

New D.I.C Head
*

Joined: 7 Jul, 2008
Posts: 19

I am asking a very basic question. I just started this online class and well i am struggling.
How do i get the program to end if the user answers my propmt with a no.

cpp
//asignment 2 to convert temperatures
//Dee Rasnake C++ class
// July 1, 2008

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

int main()

{//Declare the variables
double fairinput;
double celsout;

string input;
string y = "y";

string Bye = "BYE";

cout << fixed << showpoint;

//propt the user
cout << "Welcome to the Temperature Converter" << endl;
cout << "Enter Degrees in Fahrenheight: ";
cin >> fairinput;
cout << endl;
celsout=(fairinput-32)*5/9;
cout << setprecision(2) << endl;
cout <<"Degress in Celsius is : " << celsout
<< endl;
cout << "Continue ? (y/n) :" ;
cin >> input;
cout << endl;
if (input < y)
cout << Bye << endl;
// I want it to close if they choose n

else
cout << "Enter degrees in Fahrenheit: ";
cin >> fairinput;
cout << endl;
celsout=(fairinput-32)*5/9;
cout << setprecision(2) << endl;
cout <<"Degress in Celsius is : " << celsout
<< endl;[/color]
return

system("PAUSE"); //This is the only way i can get it to hold the screen..How Come???
}




I hope some one can help...It hard doing it online with little comprehension......thanks Dee
User is offlineProfile CardPM
+Quote Post

gabehabe
RE: Fahrenheit To Celsius
7 Jul, 2008 - 01:03 PM
Post #2

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,556



Thanked: 99 times
Dream Kudos: 2650
Expert In: ruling the world.

My Contributions
First off, welcome to </d.i.c> smile.gif

Second, please code.gif

Third, moved to the correct forum. smile.gif

Fourth, changed to title to a more descriptive one.

And finally, here is a possible solution:

You could use a do/while loop, and use cin.get() to hold it open.

Here:
cpp
//asignment 2 to convert temperatures
//Dee Rasnake C++ class
// July 1, 2008

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

int main()

{//Declare the variables
double fairinput;
double celsout;

char input; // make this a char

cout << fixed << showpoint;

//propt the user
do {
cout << "Welcome to the Temperature Converter" << endl;
cout << "Enter Degrees in Fahrenheight: ";
cin >> fairinput;
cout << endl;
celsout=(fairinput-32)*5/9;
cout << setprecision(2) << endl;
cout <<"Degress in Celsius is : " << celsout
<< endl;
cout << "Continue ? (y/n) :" ;
cin >> input;
cout << endl;
} while (input != 'n' && input != 'N');
cin.get (); // more useful way of holding the window open
return EXIT_SUCCESS; // successful execution
}

Hope this helps smile.gif
User is offlineProfile CardPM
+Quote Post

debeth
RE: Fahrenheit To Celsius
7 Jul, 2008 - 03:20 PM
Post #3

New D.I.C Head
*

Joined: 7 Jul, 2008
Posts: 19

biggrin.gif I will post in the
CODE
----

but i thought this was the right forum???? C++ right...
please bear with me....i will figure it out thanksss DEE






QUOTE(gabehabe @ 7 Jul, 2008 - 02:03 PM) *



First off, welcome to </d.i.c> smile.gif

Second, please code.gif

Third, moved to the correct forum. smile.gif

Fourth, changed to title to a more descriptive one.

And finally, here is a possible solution:

You could use a do/while loop, and use cin.get() to hold it open.

Here:
cpp
//asignment 2 to convert temperatures
//Dee Rasnake C++ class
// July 1, 2008

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

int main()

{//Declare the variables
double fairinput;
double celsout;

char input; // make this a char

cout << fixed << showpoint;

//propt the user
do {
cout << "Welcome to the Temperature Converter" << endl;
cout << "Enter Degrees in Fahrenheight: ";
cin >> fairinput;
cout << endl;
celsout=(fairinput-32)*5/9;
cout << setprecision(2) << endl;
cout <<"Degress in Celsius is : " << celsout
<< endl;
cout << "Continue ? (y/n) :" ;
cin >> input;
cout << endl;
} while (input != 'n' && input != 'N');
cin.get (); // more useful way of holding the window open
return EXIT_SUCCESS; // successful execution
}

Hope this helps smile.gif


User is offlineProfile CardPM
+Quote Post

Delta_Echo
RE: Fahrenheit To Celsius
7 Jul, 2008 - 08:22 PM
Post #4

D.I.C Regular
***

Joined: 24 Oct, 2007
Posts: 439


My Contributions
MMO, take you shitty spam bot off the forum. Ass hole.


Now, in response to the forums intent.

I suggest using an if statement. Here is an Example:
cpp

#include <iostream>

using namespace std;

int main(){

int m_menu;

cout << "Menu: ";
cout << "\n\n1. Choice One\n";
cout << "2. Choice Two\n";
cout << "> ";
cin >> m_menu;

if ( m_menu == 1){
cout << "You chose One!\n";
cin.get();
return 1;
}
if ( m_menu == 2){
cout << "You chose Two!\n";
cin.get();
return 1;
}
else {
cout << "You chose neither!\n";
return 1;
}
}


You can also use the switch statement:
CODE


switch{ //Declaration of a switch
case (value to check for): { Statement to execute}
case (value to check for): {Statements}
default {statements to execute if no other case was met!}
} // End



Hope that helps!
Good Luck! :-)
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 12:50PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month