### 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.)
 ``1234567891011121314151617`` ``````#include using namespace std; int main() { int x,count=0,max,min,av,num; do{ cout<<"enter a number"<>num; count=count+1; while (num>x) cout<<"enter a number"<

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.
please can u be more specific
you cant use else without if...
 ``123456789101112131415161718192021222324252627`` ``````# include 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.