4 Replies - 396 Views - Last Post: 27 January 2010 - 09:12 PM Rate Topic: -----

#1 nevereap  Icon User is offline

  • New D.I.C Head

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

How to do somethings with loop

Post icon  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. :pirate:

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  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5345
  • View blog
  • Posts: 27,296
  • Joined: 10-May 07

Re: How to do somethings with loop

Posted 27 January 2010 - 08:45 PM

View Postnevereap, 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?
Was This Post Helpful? 0
  • +
  • -

#3 seeP+  Icon User is offline

  • D.I.C Addict

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

Re: How to do somethings with loop

Posted 27 January 2010 - 08:46 PM

How about a linked list.

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

Was This Post Helpful? 0
  • +
  • -

#4 nevereap  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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)
	{
	double add;
	
	add=add+Input_number;
	cout << "Enter number [float or 'e' to end.]:  ";
	cin >> Input_number;
	cout << add;
	}

Was This Post Helpful? 0
  • +
  • -

#5 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1074
  • View blog
  • Posts: 4,533
  • Joined: 09-June 09

Re: How to do somethings with loop

Posted 27 January 2010 - 09:12 PM

  
  double add; //your reinitializeing every loop
	
	add=add+Input_number;




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
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1