Need assistance with a simple program

Hey forum,

I just started a class in C++ and have no idea how to do an assignment.

Here it is:

Calculating Basic Statistical Information

In this assignment, you will write a program that calculates basic statistical information from aggregate game-playing data. Your program will input several pieces of information about the games from standard input, calculate additional information, and then direct it to standard outputs. Specifically, you will obtain the following information from standard input:

* the total number of players
* the total number of hours played
* the total number of points scored
* the total number of games played

You may assume that all of this data will be integers. Using this data, you will calculate and direct to standard output the following information:

* the average hours per player
* the average points per player
* the average points per game
* the average points per hour per player

Because you do not know what the input data will be, the output data may be floating point data. The output must be formatted with labels; do not simply output a series of numbers. For example, if the following data were input:

Enter total number of players: 10
Enter total number of hours played: 100
Enter total points earned: 1000
Enter total number of games played: 10

The output should look like the following:

Average hours per player: 10
Average points per player: 100
Average points per game: 100
Average points per hour per player: 10


I do not know how to start it.

Please help. . .
Hi

Just posting your problem here won't get you much help, make an effort at writing some code which attempts this problem and post it here, then we can help you.
We are not going to give away homework solutions. Tell us what you have problems with. At the moment, it's just input, output, some variables and some arithmetic.
In this assignment, you will write a program that calculates basic statistical information from aggregate game-playing data.


So, first of all just make a programme. Completely empty, that does nothing, but compiles and runs.

Your program will input several pieces of information about the games from standard input


Then, add some code to take something from standard input.

If you get stuck on either of these two, come back with what you have and show us.
Alright I know i start with this:

#include <iostream>

using namespace std;

int main()
{

but what next? I have no idea so I cannot attempt much more if at all.
Do not do this:

using namespace std;

Just how much programming have you done before? Do you know what any of the following things are? Variable, function, type.
I know that a function is basically any statements that is executed when it is called from the program.

Variables are like in algebra such as a, b, c that hold something.

and types are like bool, int etc.

I havnt taken much programming
In that case this problem is too advaced for you and you should learn the basics

http://cplusplus.com/doc/tutorial/
I wrote this:

#include <iostream>

using namespace std;

int main()
{
int num1;
int num2;
int num3;
int average;

num1 = 0;
num2 = 0;
num3 = 0;
average = (num1 + num2 + num3) / 3;

cout << "num1 = " << num1 << endl;
cout << "num2 = " << num2 << endl;
cout << "num3 = " << num3 << endl;
cout << "average = " << average << endl;

system("PAUSE");

}

This program works.

I am unsure how to do the problem in the first post.
Your difficulties are not with programming; your first problem is in actually deciding what you want to do. Your difficulties are in basic mathematics.

You will make use of a number of basic operations in this programme. I suggest you start by ading comments to your empty programme, explaining each step that you wish to take:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

int main()
{
   // create variable to store  the total number of players

   // Fetch total number of players from user and store that number in the variable

  //  More things like that...

   //  Calculate average hours per player using basic algebra

   // Output to screen average hours per player

  // More like that

return 0;
}


Once you have actually solved the problem by thinking about it, it becomes simply a matter of turning your steps into code.
Last edited on
Thank You Moschops,

so i do need :

using namespace std; ?
I advice you take the programming tutorial on these websites:
http://www.cplusplus.com/doc/tutorial/
http://xoax.net/comp/cpp/console/

Also, disregard Moschops advice. It's perfectly fine to use that. (Using it in a header file should not be done, but for programs (main.cpp's), it's fine.)

Finally, if you are thrown into the dark just like that by some school, I'd suggest you seriously doubt the usefulness of said school.

--

Main is a function by itself, it represents the program as it is executed at runtime. Every statement you plunge into it will be executed.

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream> // Add proper libraries

using namespace std; // Something you need not care about at this moment

int main()
{
   cout << "Hello world!" << endl; // Print Hello world! followed by a newline
   cout << 3 << endl; // Print 3 followed by a newline

   int a = 7; // Initialize a new integer variable a
   cout << a << endl; // Print the value stored by a followed by a newline
   system("pause"); // Only use this for testing purposes or when instructed to add this
}



EDIT:
While I was writing my comment, all you guys reacted... Well, just take what you can still use from my post.
Last edited on
Also, disregard Moschops advice. It's perfectly fine to use that.


It is fine. It wrecks the namespace, but in a cpp file you'll probably only wreck things for yourself.
Thanks Kyon,

That is helpful.
look at xoax's tutorials and understand them, they'll "teach you how to fish", your assignment is asking you whether you know the basics
Alright I have this much code:

#include <iostream>

using namespace std;

int main()

{
int iPlayers;

int iHours;

int iPoints;

int iGames;


cout << "Enter in The Total Number of Players: " << endl;

cin >> iPlayers

cout << "Enter in The Total Number of Hours Played: " << endl;

cin >> iHours

cout << "Enter in The Total Number of Points Scored: " << endl;

cin >> iPoints

cout << "Enter in The Total Number of Games Played: " << endl;

cin >> iGames

system("PAUSE");

}


Firstly is that good/accurate for the assignment?

Also why can't I input what I am asking for?
you left return 0; after system pause.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>

using namespace std;

int main()

{
int iPlayers; 

int iHours;

int iPoints;

int iGames;


cout << "Enter in The Total Number of Players: " << endl; 

cin >> iPlayers;

cout << "Enter in The Total Number of Hours Played: " << endl; 

cin >> iHours;

cout << "Enter in The Total Number of Points Scored: " << endl; 

cin >> iPoints;

cout << "Enter in The Total Number of Games Played: " << endl; 

cin >> iGames;

//average hours per player
//create new container to store average hours per player

int iaverage_player_hrs = iHours/iPlayers; /*here I've done simple maths of averages 
(its stored in the new (int) container          iavarage_player_hrs   )*/

cout <<" The average player hrs is          "<< iavarage_player_hrs<<endl<<endl;

int iaverage_player_points = iPoints/iPlayers; /* this is the same thing I've done above*/

cout <<" The average player points is          "<< iaverage_player_points<<endl<<endl;

int iaverage_points_game = iPoints/iGames; /* this is the same thing I've done above*/

cout <<" The average game points is          "<< iaverage_points_game <<endl<<endl;


int  iaverage_points_per_hour_per_player = iaverage_player_points/iaverage_player_hrs;
cout <<  " the average points per hour per player is      " << iaverage_points_per_hour_per_player << endl;

system("PAUSE");

return 0;

}


this is your problem solved, if not tweak it.

look at xoax.net's c++ tutorials on youtube since you desperately need them. They are the best on youtube, trust me on my months experience.

Please not that c++ required dedication, and sadly debugging is the best teacher, sadly it is very painful in the beginning.
Hey Forum,

For some reason I can not Enter in any information into the command screen.

It just disappears instantly.

Any Solutions?
What program are you using? to compile, write, ect.
Last edited on
Visual C++ 2008 Express
Topic archived. No new replies allowed.