how do i goo about this

The heating system in a school should be switched on if the average temperature is less than 17 degrees celcius. The average temperature is found from the temperatures in the art english and music departments. You are required to write a C++ program that allows the user to input 3 temperatures. The program calculates and displays the average temperature and then displays "heating should be on " or " heating should be off" as appropriate.

Declare 3 int variables for the temperatures in the art, English, and music departments. Use cout to tell the user to input the temperatures for the 3 departments, then get the input from the user using cin, like this:

std::cin >> artTemperature;

If you put using namespace std; at the top of your program, you don't have to write 'std::' before cin. Once you do this for all 3 variables, create a double called average, and set it equal to the sum of all 3 temperature variables, divided by 3.0. Use an if statement to check if the average temperature is less than 17 degrees, and if it is, print "Heating should be on", and if not, print "Heating should be off".

That's the best explanation I can come up with without writing the code for you.
Last edited on
that allows the user to input 3 temperatures

http://www.cplusplus.com/doc/tutorial/basic_io/

calculates and displays the average temperature
 
double avg = (tempArt + tempEnglish + tempMusic) / 3.0;


then displays "heating should be on " or " heating should be off" as appropriate.

http://www.tutorialspoint.com/cplusplus/cpp_if_else_statement.htm
this is what i came up with

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49

#include <iostream>
#include <cmath>
using namespace std;

int main()

{

int tempArt;
int tempEnglish;
int tempMusic;
double avg = (tempArt + tempEnglish + tempMusic) / 3.0;

do
{
        cout<<"Please enter Art Temperature and press Enter.";
        cin >> tempArt;
        

        cout << "Please enter English Temperature and press Enter.";
        cin >> tempEnglish;

        cout << "Please enter Music Temperature and press Enter.";
        cin >> tempMusic;



        if(avg <= 17)
        {
           cout << "heating should be on: " << avg << endl;
        }

        else if (avg >= 17)
        {
            cout << "heating should be off: " << avg<< endl;
        }

        cout << "Do you want to continue enter Y or N to stop: ";
        cin  >> yesno;
        yesno = toupper(yesno);

    }while (yesno == 'Y');


    // system ("pause");
    return 0;
}

you have to do your calculation on line 13 AFTER you've got the values from the user. i.e. move line 13 to line 27.
and initialise your variables on lines 10,11 and 12.

if the average temperature is less than 17

you need to change line 29 to:
if(avg < 17)
Deja vu ... same poster, same topic, the other two threads:
http://www.cplusplus.com/forum/beginner/170094/
http://www.cplusplus.com/forum/beginner/170240/


Note on true/false.
A number is either less than X or not. There are no if's about it.
IF foo<=X is false, THEN there is no need to test whether X<foo, because it is true by definition.

The foo<=X is same as (foo<X OR foo==X). IF foo<=X is false, THEN foo==X is false too, so testing (X==foo OR X<foo) is sure to fail its "is equal?" part.
Topic archived. No new replies allowed.