c++ create a program please somebody helpp..

closed account (9N7koG1T)
Part 0

Output a prompt using the cerr object that instructs the user to type in a temperature in °F (i.e. Fahrenheit).

Define a variable named tempF of type int.

Read the input into the tempF variable using the cin object.
cin >> tempF;

Define a variable named tempK of type double.

Convert the °F value to Kelvin using the following arithmetic expression storing the result of the expression in the tempK variable.
(tempF + 459.67) * 5 ÷ 9

Use the cout object to print the following output.
tempF degree Fahrenheit in Kelvin is tempK

Example output when the input is 72.
72 degree Fahrenheit in Kelvin is 295.372

Be sure to end the output of this part with a newline.

Part I

Insert the following statement into your program.
cout << 5/9 << endl;

Using only one cout statement, print a short explanation as to why the previous cout statement printed the value 0 (zero).
cout << "5/9 prints 0 because ..." << endl;
Last edited on
What's wrong with your code? Can you tell us what compile errors you're getting, show us the entire code, and tell us which lines are giving you the errors?
closed account (9N7koG1T)
I just started to learn this program, I dont want to write here because I'm sure there are lots of errors in code..
closed account (9N7koG1T)
If you know the answer please write, I really need to know :( I tkink,it takes a couple minutes for programmer.. please :(
We don't give direct answers to homework problems.
http://www.cplusplus.com/articles/DjGEy60M/
closed account (9N7koG1T)
ok, I will try to solve then I will write.
part 0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
using namespace std;

int main(){
    int tempF;
    double tempK;

    cout << "Type a temperature in Fahrenheit and press ENTER: ";
    cin >> tempF;

    tempK = (tempF + 459.67) * 5 / 9;

    cout << tempF << " degree Fahrenheit in Kelvin is " << tempK << endl;

    cin.get();
    return 0;
}

i think you can do part 1
Last edited on
Part 1 is just understanding integer division, which you actually got lucky with in your program due to order of operations. ;)
closed account (9N7koG1T)
...
..
.
cout << tempF << " degree Fahrenheit in Kelvin is " << tempK << endl;
cout <<"5/9 prints 0 because in C++ the result of dividing an integer by an integer is truncated to an integer <<

endl;

}

Is that enough? what is these for--cin.get(); and return 0; Do I have to write?
It's generally a bad idea to mix cin.get with cin so you should just leave it out and have the program end with "return 0;", which basically ends the main function as false - ending the program.

Your answer to Part 1 looks fine so long as you're formatting it correctly:
1
2
cout << tempF << " degree Fahrenheit in Kelvin is " << tempK << endl;
cout << "5/9 prints 0 because in C++ the result of dividing an integer by an integer is truncated to an integer" << endl;
Last edited on
@whitewind do you think he's using windows or linux?
closed account (9N7koG1T)
I am using windows, if I write this way, any problem?
what compiler are you using, dev c++ ?
I sure hope neither of you is using Dev-C++:
http://www.cplusplus.com/articles/36vU7k9E/
ii usually run linux and when ii use windows ii run qt
but it seems a lot of people use dev when they begin programming
closed account (9N7koG1T)
I am using Dev c++
Wait. Why is "tempK" double? Surely it should be int?
Vortex, degrees K is not an integer. It's 273.15 for the freezing point and conversion from F to K uses a fraction and a decimal real.

Since it's also an SI unit, it should be taken to degree of precision.
Last edited on
I am using Dev c++


mmhm so you're gonna need to use cin.get() or system("PAUSE") in order to keep the cmd from closing.
cin.clear(); cin.sync(); cin.ignore(unsigned(-1), '\n');
Topic archived. No new replies allowed.