Thread: help

  1. #1
    Unregistered
    Guest

    help

    need help with assignment
    Csci 151 Spring 2002 March 12, 2002

    Use the VC++ IDE on the lab pc’s to create a program that allows the user to enter )from the keyboard) from 2 to 5 numbers and calculate the average of the numbers entered. Display the average to the screen. If the answer has a zero fractional part, display it. That is, don’t just display the whole number (e.g. 5 numbers totalling 25 would be 5 for an average, but display 5.0 )

    Allow the user to reset and find another average and keep doing this until they wish to quit. Don’t force them to end the program and begin again each time they want an average of a series of numbers.

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    dont sleep when your teacher explains this to you!

  3. #3
    Unregistered
    Guest
    *whisper*.......I have just one word for you........loops!

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    this is something u learn after "hello world"
    so if u had been listening to your teacher u would have
    written it by yourself

  5. #5
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802

  6. #6
    Unregistered
    Guest
    I'm a 12 year old kid and I reckon I can do that. Let me try.
    It might just take some time.

  7. #7
    Registered User
    Join Date
    Apr 2002
    Posts
    24
    I'm 15. i have been learning C++ for under a week and i also think i could.
    #include <iostream.h>
    int main()
    {
    cout<<"Hello";
    return 0;
    }

  8. #8
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    I'm 14 and im the only one which thinks he can do it and then does it.




    Code:
    #include <iostream.h>
    #include <conio.h>
    
    int times = 0;
    int numbers[5];
    float total;
    
    int main(void) {
    	
    	while(times<2||times>5) {
    		cout << "How many numbers do you want to enter? (min 2 max 5)\n\n";
    		cin>>times;
    	}
    		for(int count = 1; count<(times+1); ++count) {
    		cout << "\n\nEnter "<< count;
    		switch(count) {
    		case 1:
    			cout << "st";
    		break;
    		case 2:
    			cout << "nd";
    		break;
    		case 3:
    			cout << "rd";
    		break;
    		case 4:
    		case 5:
    			cout << "th";
    		break;
    		}
    		cout << " number: ";
    		cin >> numbers[count];
    		total+=numbers[count];
    	}
    	cout << "\n\n\nAverage is: " << total/times << "\n\n";
    	getche();
    return 0;
    }
    Last edited by ErionD; 04-27-2002 at 11:09 AM.

Popular pages Recent additions subscribe to a feed