• Advertisement
Sign in to follow this  

C++ exercise help(using Dev-C++ compiler)

This topic is 4865 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a beginnig C++ book and it has an exercise as follows: Write a program that gets three game scores from the user and displays the average. Could you show me the code and tell me what it means if in case I do this again?

Share this post


Link to post
Share on other sites
Advertisement
Isn't the point of the exercise being in the book to give you a chance to PRACTICE what you just learned?

Did you uh, read the chapter? I'm sure they introduced a function to "AverageThreeInts" or whatever, so maybe you should read over it.

On a better note, I'm glad you're actually sortof attempting the exercises in the book, it'll help you in the long run.

Just remember, you need to display to the user that you need 3 numbers (If you're just starting out, I'd seperate the numbers into three prompts), get input from the numbers, store them in variables, and average them.

You can do it.

Share this post


Link to post
Share on other sites
ive tried i really have. I just don't know how and it would really helpme learn If sum1 told me how to do it so I can undertand it for the future. I'm a newb to programming and it would honestly only help me.

Share this post


Link to post
Share on other sites
Here, how about this


#include <iostream>

using namespace std;

main()
{

int numb_one;
int numb_two;
int numb_three;
int all_numb;
int average;

cout<<"Input 3 numbers\n";
cout<<"1. ";
cin >> numb_one;
cout<<"\n"
cout<<"2. ";
cin >> numb_two;
cout<<"\n";
cout>>"3. ";
cin >>numb_three;
cout<<"\n\n";

all_numb = numb_one + numb_two + numb_three;
average = all_numb / 3;

cout<<"Your average is << average <<\n";

return 0;

}



---------------------------------------------------------------
maybe this will give you some idea and a better understanding.

As you can tell I asked the user to input 3 numbers, or scores?..and then I overloaded in a variable called all_numb..then dividing by 3 and assigning it to average.
Last I Output The average to the screen.

[Edited by - hangmansjoke on October 28, 2004 12:19:11 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement