Thread: C++ loops

  1. #1

    Question C++ loops

    Code:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {   
        int avger=0;
        cout<<"Enter a number:\n";
        cin>> avger;
        for (int avge=0; avger >= 0 < avger; avger++){
            cout << avger <<endl;
        }
        cout << "The average is:\n" << avger <<endl;
            
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    How would i make this average out all number from 0 to the number they enter like (5(1,2,3,4,5=15/5=3) how can i do this

  2. #2
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    Code:
    	int up_to;
    	int count = 0;
    	cin >> up_to;
    
    
    	for(int i = 1; i <= up_to; i++)
    	{
    		count = count + i;
    	}
    
    	cout << count/up_to;

  3. #3
    thxs you saved me for honors credit

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Too many loops D:
    By F5 Tornado in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2007, 01:18 AM
  2. loops with incrementing strings .... ?
    By twomers in forum C++ Programming
    Replies: 1
    Last Post: 12-12-2005, 11:29 AM
  3. strings and loops...
    By twomers in forum C Programming
    Replies: 5
    Last Post: 12-12-2005, 11:28 AM
  4. help with arrays and loops
    By jdiazj1 in forum C Programming
    Replies: 4
    Last Post: 11-24-2001, 04:28 PM
  5. for loops - newbie q's
    By Narciss in forum C Programming
    Replies: 8
    Last Post: 09-26-2001, 02:44 AM