find how many temperatures were hotter than 22 and how many were colder than 10(code inside)

Guys, I'm trying to write a program:

Write a program that will find how many temperatures were hotter than 22 and how many were colder than 10 (using functions), after that print if there were more hotter or colder temperatures.

but I'm having problems with strings, I'm still not sure if I'm using them properly so if someone could check my errors and help me out in this program I'd be very thankful.

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
  #include <iostream>

using namespace std;

int bigger(int s)
{
    int b=0;
    if(s>22)
    {
        b=b++;
        return b;
    }
}
int smaller(int d)
{
    int c=0;
    if(d<10)
    {
        c=c++;
        return c;
    }
}
int main()
{
    int i;
    int temperatures[10];
    for(i=0;i<10;i++)
    {
        cout<<"Enter the temperatures" <<endl;
        cin>>temperatures[i];
    }
    cout<<"The number of temperatures hotter than 22 is:"<<bigger(temperatures[10])<<endl;
    cout<<"The number of temperatures colder than 22 is:"<<smaller(temperatures[10])<<endl;
    if(bigger(temperatures)>smaller(temperatures))
    cout<<"There were more hotter temperatures"<<endl;
    else
        cout<<"There were more colder temperatues"<<endl;
    return 0;
}
Your functions bigger and smaller and taking int instead of array.
Then you need to put for loops on both functions to go through the whole array.

At lines 32 and 33 you need to pass temperatures instead of temperatures[10]

And you can remove int i at line 25 and put it in for loop at line 27.
Thank you, however I'm not very good with arrays do you think you could help me out fixing it? I would be very thankful if you can get my mistakes fixed. Thanks
int smaller(int d) to int smaller(int d[]) at line 14.
Then similar trick to bigger in line 5.
Last edited on
as jezze said you need to loop through your array in your functions. use a similar method to how your reading values into an array on lines 27-31, but get the value out rather than setting it.

edit: do you have to use c-style arrays?
Last edited on
Topic archived. No new replies allowed.