The question is:
Write a C++ program that will read temperature and degrees fehrenheit and convert it to degree celesius.
celesius=5/9(fahrenheit-32).
It may be very easy to other but I'm an ameature in C++.
please help :(
Printable View
The question is:
Write a C++ program that will read temperature and degrees fehrenheit and convert it to degree celesius.
celesius=5/9(fahrenheit-32).
It may be very easy to other but I'm an ameature in C++.
please help :(
No one will write full code for you...show some efforts...whereever you are stuck...post it....someone will definetly help you
Well to begin with you are gonna need a function that would translate from C to F, and from C to F
and then in the main function you are gonna need to ask for the degreese and run the apropriate function.
Maybe this will help, just a few days old:
http://cboard.cprogramming.com/showthread.php?t=70535
It is the reverse of your problem.
Code:#include<iostream>
using namespace std;
int main()
{
float fahr; //holds user entered degrees in Fahrenheit
float cels; //holds our calculated degrees in Celsius
cout << "Enter degrees in Fahrenheit: ";
cin >> fahr; //Get user input
cels = (((fahr-32)/9)*5); //Equation to convert F to C
cout << fahr<<" degrees equals "<< cels << " degrees in Celsius"<< endl; //Output answer
system("PAUSE"); //Pause so you can read the answer
return 0;
}
Evidently not. Please do not post questions asking for people to write your entire program. Come to the forums with a specific question and show that you have already tried. Equally annoying, do not encourage this behavior by GIVING people their entire program.Quote:
No one will write full code for you
Please refer to the forum rules:
http://cboard.cprogramming.com/annou...ouncementid=51
I'm sorry but it was such an easy program that explaining it is longer than writing it. I couldn't help it. I commented to show him how it was done.
What if you want to go from Cels to fah?
you can create the functions:
Code:int FC(int f)
{
return (f - 32) * 5/9
}
int CF(int c)
return (c * 9/5) +32
}
He didn't say he needed to go from Celsius to Fahrenheit, but yes you could have made the equation into a function.
Thank you all for helping me out and i'm sorry that i had make go through all of this.
And by the way you are right i should specifie my question.
Anyway i only had two classes in C++ and i have no backeground on this subject.
Again thank u all for help. :)
Here is a little code you can try:
Code:#include<vector>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<windows.h>
using namespace std;
class Temp
{
public:
void menu();
double f_to_c(char* fehrenheit);
char* get_user_input();
void display_answer(char* fehrenheit, double celcius);
bool again();
private:
vector<char> user_input;
};
void clrscr();
int main()
{
Temp *MyTemp;
char *f_temp;
do
{
MyTemp->menu();
f_temp = MyTemp->get_user_input();
MyTemp->display_answer(f_temp, MyTemp->f_to_c(f_temp));
}while(MyTemp->again());
return EXIT_SUCCESS;
}
void Temp::menu()
{
clrscr();
cout << endl << endl << endl << endl
<< setw(40) << "+----------------------------+\n"
<< setw(40) << "| +------------------------+ |\n"
<< setw(40) << "| | | |\n"
<< setw(40) << "| | Fehrenheit to Celcius | |\n"
<< setw(40) << "| | | |\n"
<< setw(40) << "| | Temperature Converter | |\n"
<< setw(40) << "| | | |\n"
<< setw(40) << "| +------------------------+ |\n"
<< setw(40) << "+----------------------------+\n";
}
char* Temp::get_user_input()
{
char input, *f_temp;
cout << endl << endl
<< setw(20) << "Enter temperature in degrees fehrenheit : ";
cin.get(input);
while(input!='\n')
{
user_input.push_back(input);
cin.get(input);
}
f_temp = new char[user_input.size()];
for(int i=0, back=user_input.size(); i<back; i++)
f_temp[i] = user_input[i];
return f_temp;
}
double Temp::f_to_c(char* f_temp)
{
double f;
f = static_cast<double>(atof(f_temp));
return(((f-32)/9)*5);
}
void Temp::display_answer(char* fehrenheit, double celcius)
{
cout << endl << endl;
cout << static_cast<double>(atof(fehrenheit)) << "F equals " << celcius << " degrees celcius.";
}
void clrscr()
{
COORD coordScreen = { 0, 0 };
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsole, &csbi);
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
FillConsoleOutputCharacter(hConsole, TEXT(' '),dwConSize, coordScreen, &cCharsWritten);
GetConsoleScreenBufferInfo(hConsole, &csbi);
FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
SetConsoleCursorPosition(hConsole, coordScreen);
}
bool Temp::again()
{
char choice;
cout << "\n\nWould ye' like to try again?";
cin.get(choice);
switch(toupper(choice))
{
case 'Y': return true;
break;
case 'N': clrscr();
return false;
break;
default: cout << '\a';
again();
}
}