plz help me for this code

Write your question here.
Write a c++ program that initially takes an integer value from the user as the loop’s limit. It means that the loop will execute the same times as the input from the user. The loop will then take integer values as input from the user until it reaches loop limit.
You are required to use only one variable which will be used to take input repeatedly from the user inside the loop. It means you are not allowed to use the array or multiple variables for this purpose. After that your program will calculate sum of entered values, their average, minimum and maximum values along with position on which these values were entered.

NOTE: You can use different variables for storing the values for sum, average, minimum and maximum numbers etc. The restriction of using a single variable is just for getting input repeatedly inside the loop.

we won't do your homework. post the code you have so far.
The tricky part here is that you can't store all the input numbers, so you have to update the result data as you read each number.

I suggest that you create variables for
- the number of values N
- the current value
- the sum of all values
- the position and value of the minimum number
- the position and value of the maximum number

Each time through the loop you read a new value, update the sum, and possibly update the min & max values/positions (if the new value read is the largest or smallest value so far).

When you're done you can print out all the details. You'll compute the average as sum/N.


closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/179704/

Duplicate post
now how i m take the sum of the values that enter by user during process of loop because every time user giving input value the value is change in next turn of loop i want to solve this problem before 1 dec plz help guys thats the source code i write till,
#include <iostream>

using namespace std;
main()
{
int l,count,sum,average,minimum,maximum,n;
cout<<"how many times loop run plz enter";
cin>>l;
for(n=0,count=1;count<=l;count++)
{
cout<<"plz enter the first" <<count<<"value";
cin>>n;

}
}
Just a couple of things in your code. I would recommend that you indent the code, as well.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

using namespace std;
main()   // It should be int main()
{
int l,count,sum,average,minimum,maximum,n;
cout<<"how many times loop run plz enter";
cin>>l;
for(n=0,count=1;count<=l;count++) // Wrong format of for loop. It should have not more // than three arguments. Example for (int x = 0; x < l ; x++)
{
cout<<"plz enter the first" <<count<<"value";
cin>>n;

}
}


Proposed Pseudocode to give you an idea.
Declare the variables.
Ask the user to input the max numbers of integers in the loop to add.
Run a for loop, which does not exceed the number the user inputted.
For each number the user enter, establish a running total for the sum variable.
If the number is less than the minimum value, then the number is the minimum value.
Record the position of the minimum value
If the number is higher than the maximum value, then the number is the maximum value.
Record the position of the maximum value
Calculate the average by dividing the sum variable divide by the max number of integers in the loop to add.
Notify the user the sum of the integers
Notify the user the average of the numbers
Notify the maximum number to the user and its position
Notify the minimum number to the user and its position

I wrote the code (I am not going to give it away, though) and to show you the output it below.

Input the maximum number of loops to add: 6
Enter integer number 1 :88
Enter integer number 2 :22
Enter integer number 3 :55
Enter integer number 4 :66
Enter integer number 5 :1
Enter integer number 6 :99
The sum of the numbers is 331
The average of the numbers is 55
The maximum number is 99 at position number 6
The minimum number is 1 at position number 5


Last edited on
thanks chicafeo for your kind suggestion i already write the code its ok don't share your code with me
Topic archived. No new replies allowed.