I just started my degree and would appreciate some help from you.
Here is one of the Exercises in my book,I am not sure if its done correct according to assignment statement or not. Many thanks
Lorraine inherited her grandmother's old cookbook, but all the oven temperatures are given in Fahrenheit,
and her oven is only calibrated in Celsius. Write a program to help her..
1 2 3 4 5 6 7
float fahrenheit,celsius;
cout<<"fahrenheit to celsius"<<endl;
cout<<"Enter the temperature in Fahrenheit: ";
cin>>fahrenheit;
celsius=(fahrenheit-32)*5/9;
cout<<"celsius: "<<celsius<<endl;
return 0;
You need to put this code inside int main() and you need to include the required libraries for your program to run.
For this code you will need: #include <iostream>
also, write this under your includes:
usingnamespace std;
some people will hate me for that but don't worry about it.
One more thing, your console may shut down quickly before you could see anything, so we have to use system("PAUSE") before return 0.
People will hate me for that but you're a beginner and I think it will do the work for now.
so it will be like this:
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
usingnamespace std;
int main(){
float fahrenheit,celsius;
cout<<"fahrenheit to celsius"<<endl;
cout<<"Enter the temperature in Fahrenheit: ";
cin>>fahrenheit;
celsius=(fahrenheit-32)*5/9;
cout<<"celsius: "<<celsius<<endl;
system("PAUSE");
return 0;
}
Pretty sure he has already done everything you said in your post, but just didn't show it here >.>. He is simply asking if his solution is done correctly and if it can be done better ^^
@OP
Looks good. I would avoid using namespace std though, use std:: instead. You can google that to find out why :)
1 2 3 4 5 6 7 8 9 10 11 12 13
#include <iostream>
int main()
{
float fahrenheit, celsius;
std::cout << "fahrenheit to celsius" << std::endl;
std::cout << "Enter the temperature in Fahrenheit: ";
std::cin >> fahrenheit;
celsius = (fahrenheit - 32) * 5.0 / 9.0;
std::cout << "celsius: " << celsius << std::endl;
return 0;
}