# How to do somethings with loop

Page 1 of 1

## 4 Replies - 700 Views - Last Post: 27 January 2010 - 09:12 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=152381&amp;s=7941eaae47c48b14c2c4edbbd963228a&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 nevereap

Reputation: 0
• Posts: 4
• Joined: 27-January 10

# How to do somethings with loop

Posted 27 January 2010 - 08:44 PM

```#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
int main ()
{
double Input_number;

cout << "Enter a non-number e to stop entering numbers.\n";
cout << "Enter number :  ";

while(cin >> Input_number)
{
cout << "Enter number [float or 'e' to end.]:  ";
Input_number
}
return 0;
}
```

Ok, this is what i have right now. What I want to know to how to get is the "x" amount of numbers from the user input.
For example. If the user inputs 1, 2, 3, and 4 from the loop, and the output average is 10/4. I want to figure out how to get all the variables into one number. like x1,x2,x3,and x4 into one number or individually so i can make a statement to calculate with. Then I would also please like to know how to get the number of inputs into a variable. Like since there are 4 inputs how would like get 4 inputs to use as a variable?
PS. The user can input as many numbers as he/she wants, i just want to know how to get those numbers with a loop. thanks very much.

This post has been edited by nevereap: 27 January 2010 - 08:45 PM

Is This A Good Question/Topic? 0

## Replies To: How to do somethings with loop

### #2 no2pencil

• Professor Snuggly Pants

Reputation: 6642
• Posts: 30,931
• Joined: 10-May 07

## Re: How to do somethings with loop

Posted 27 January 2010 - 08:45 PM

nevereap, on 27 Jan, 2010 - 09:44 PM, said:

I want to figure out how to get all the variables into one number.

Will the user always enter a number less than 10? Once the numbers are "one", how would you know placement?

### #3 seeP+

Reputation: 55
• Posts: 601
• Joined: 20-July 09

## Re: How to do somethings with loop

Posted 27 January 2010 - 08:46 PM

This post has been edited by seeP+: 27 January 2010 - 08:48 PM

### #4 nevereap

Reputation: 0
• Posts: 4
• Joined: 27-January 10

## Re: How to do somethings with loop

Posted 27 January 2010 - 09:01 PM

i has a quick chat with a guy in the hall, and he said i should for example define sum, then if i wanted to find the sum of all the input numbers it would be like, and with the amount of input i would just use count function i think. Is this right?
```while(cin >> In_number)
{

cout << "Enter number [float or 'e' to end.]:  ";
cin >> Input_number;
}
```

### #5 jjl

• Engineer

Reputation: 1270
• Posts: 4,998
• Joined: 09-June 09

## Re: How to do somethings with loop

Posted 27 January 2010 - 09:12 PM

```

```

this would be better
```	double sum = 0.0;
double temp = 0.0;

while(true)
{
cout<<"ENTER NUMBER : ";
cin>>temp;
sum+=temp;
cout<<"SUM : ";
cout<<sum<<endl;

}

```

notice that it is an infinite loop though