~~Help me urgently please~~

Help please.. just gotta make the loop run as many times as the value that the user enters... i have no idea how to do it tho... :(


main.cpp
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>
#include <statistic.h>

using namespace std;

int main()
{
    int x;

    Statistic a;

    cout << "Please enter a value" << endl;
    cin >> x;

    a.printStatistics(x);

    cin.get();
    cin.get();
    return 0;
}




statistic.cpp
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 "statistic.h"
#include <iostream>

using namespace std;

void Statistic::printStatistics(int x)
{
    int max = x;
    int min = x;
    int numberOfVariables = 0;
    int i;
    long int sum = x;
    long int average = sum / numberOfVariables;

    if(x, x!= 0, x--)
     {
        cout << "Please enter other variable" << endl;
        cin >> i;
        numberOfVariables++;

        sum += i;

        if( max > i )
            max = i;
        if( min < i)
            min = i;

        cout << "The sum of the values that was entered are: " << sum << endl;
        cout << endl;
        cout << "The average of the values that was entered are: " << average << endl;
        cout << endl;
        cout << "The largest of the values that was entered is: " << max << endl;
        cout << endl;
        cout << "The smallest of the values that was entered is: " << min << endl;
    };


};



statistic.h
1
2
3
4
5
6
7
  class Statistic
{
public:
    void printStatistics(int);
};

you're using if.. instead of for loop


for(x = 0; x<value; x++)
The keyword is for not if.--line 15 printStatistics();
If is a conditional statement wuile he for is a loop.

Aceix.
Topic archived. No new replies allowed.