C++ loops

This is a discussion on C++ loops within the C++ Programming forums, part of the General Programming Boards category; Code: #include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) { int avger=0; cout<<"Enter a number:\n"; cin>> ...

  1. #1
    C++ GOD italiano40's Avatar
    Join Date
    Nov 2005
    Posts
    9

    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
    C++ GOD italiano40's Avatar
    Join Date
    Nov 2005
    Posts
    9
    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, 03:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21