Need a help..

hello guys.. i wish u could help me with this program.

Write a cplusplus programs that reads an integer as lng as they continue to be input in increasing order,that is each coming number must be a greater than or egual to the previous. as soon as the sequence is no longer increasing the program should stop and output the following:
1.how many numbers were entered <not including the last number)
2. the sum of the entered numbers(not including the last number)
3. the minimum,maximum,and average of the entered numbers(not including the last number).
a sample execution
enter a number:2
enter a number:5
enter a number:7
enter a number:0
stopped.
increasing count=3
sum=14
min=2
max=7
avg=4.666

my code is : (put its not complete i need help.)
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 x,count=0,max,min,av,num;
do{
cout<<"enter a number"<<endl;
cin>>num;
count=count+1;
while (num>x)
cout<<"enter a number"<<endl;
else
av=sum/count;
cout<<av;
}
return 0;
}


i stuck..!!!
need help.. i wish also to write using while.. not do while
Last edited on
You need to remove the space in this statement using name space std; the else on line 12 should not be there. You need a ; at the end of this statement while (num>x). This is not how you use cout av=sum/cout; cout should look like this cout << "Hello World!" << endl; The brace on line 15 should be matched with } while(num>x)
Initialize x with a value...syntax error detected: the use of "else" without an if statement.
what is the answer???!?!
please can u be more specific
you cant use else without if...
closed account (28poGNh0)
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
# include <iostream>
using namespace std;

int main()
{
    int x = 0,num = 1;// Does not matter because we got to cin It so Its value gonna change
    int count = 0,sum = 0,iMin = 9999,iMax = 0;

    while(true)
    {
        cout << "Enter you number -> ";cin >> num;
        if(num>x)
        {
            count ++;
            sum += num;
            iMin = min(iMin,num);
            iMax = max(iMax,num);
            x = num;
        }else break;
    }cout << endl;

    cout << "Increasing count = " << count << endl;
    cout << "Sum = " << sum << endl;
    cout << "min = " << iMin << endl;
    cout << "max = " << iMax << endl;
    cout << "Average = " << float(sum)/count;//This is the avg (The variable ,not the Antivirus !)
}


Enjoy
Last edited on
thanks dude ..you are a great man.
Respect
Topic archived. No new replies allowed.