how to get 5 cases to compile correctly

so i have this problem that im stucked on. i have about 5 cases to do but i don't know how to put everything together. i did the first part but i cant add everything together

for example this is case 1

1
2
cout << "Enter the temperature in Celsius: \n";
cout << "-20.0 degrees Celsius is -4.0 degrees Fahrenheit. \n";


the other case

is

1
2
cout << "Enter the temperature in Celsius: \n";
cout << "0.0 degrees Celsius is 32.0 degrees Fahrenheit. \n";


there are 3 other cases like this is similar but the second line has different numbers.

how can i put all this together to compile as one?
Is it not the intention that after line 1 there should be code to input the value, and then to calculate and output the result?

Once that is working, wrap that section of code in a loop, so that all five cases can use the same code. The loop would need some way to exit, for example by asking the user whether they want to continue of finish (y/n).

Well, that's my guess anyway.
---
Last edited on
[IMG]http://i48.tinypic.com/35k4dv5.jpg[/IMG]

i only have one correct and the others failed. how do i use the loop in this sitaution?

thanks.
Why don't you post your program for us to see?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;
int main()

{
while (true)
cout << "Enter the temperature in Celsius: \n";
cout << "-20.0 degrees Celsius is -4.0 degrees Fahrenheit.\n";

cout << "Enter the temperature in Celsius: \n";
cout << "0.0 degrees Celsius is 32.0 degrees Fahrenheit.\n";

cout << "Enter the temperature in Celsius: \n";
cout << "40.0 degrees Celsius is 104.0 degrees Fahrenheit.\n";

cout << "Enter the temperature in Celsius: \n";
cout << "70.0 degrees Celsius is 158.0 degrees Fahrenheit.\n";

cout << "Enter the temperature in Celsius: \n";
cout << "100.0 degrees Celsius is 212.0 degrees Fahrenheit.\n";

return 0;
}


any help?
Well, your code doesn't attempt to read the input, nor do any calculation. In that sense it's some distance short of being a general solution.

I don't know how the testing procedure works, presumably there is some automated testing going on? Does the test process simply run the program five separate times? If that's the case, then you don't need a loop at all, as the looping is part of the test rig.

I'm still guessing a lot, but I think you just need a single case. It will need to read the input, perform the calculation, and print the output. Probably.
Last edited on
it runs the program one time. i don't think i need to calculate it but have all of it run correctly.
I think you do need to calculate it...

otherwise there wouldn't be that "Program input" on the left side of the image you showed for each test case and it wouldn't have run your program twice.
how do i calculate it? any tips on how to start?

thanks
Well, you could use this formula:
 °F = °C  x  9/5 + 32 

Because there are decimal places involved, I suggest all your variables (in particular the ones holding the Celsius and Fahrenheit values) should be of type float. (Or double would do as well, or better).

But if you want to know how to start, then the first step is to get the input value. A recommended way is to use cin.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
using namespace std;
int main()
{
    double ctemp, ftemp;

    cout << "Enter the temperature in Celsius:" << endl;
    cin >> ctemp;
    ftemp = (ctemp * 1.8) + 32;
    cout << "Fahrenheit is."; << ftemp;
    return 0;

}


for this do i need to include all of the numbers or does it automatically converts by itself?
Topic archived. No new replies allowed.