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
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.
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.
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
usingnamespace 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.
#include <iostream>
usingnamespace 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.