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;
int iaverage_player_hrs = iHours/iPlayers;
cout <<" The average player Hours are: " << iavarage_player_hrs << endl << endl;
int iaverage_player_points = iPoints/iPlayers;
cout <<" The average player points are: "<< iaverage_player_points<<endl<<endl;
int iaverage_points_game = iPoints/iGames;
cout <<" The average game points are: "<< 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 are: " << iaverage_points_per_hour_per_player << endl;
system("PAUSE");
return 0;
}
The command prompt does not stay open so I can enter in information.
Does it compile? If the code above is exactly what you're trying to build, then it's broken and it won't compile because you're missing a semi-colon on the end of int iaverage_player_hrs, which I suspect it the typo spotted by eagle-eyed Zhuge.
You've also used system without including the appropriate header.
You are missing a semicolon on one of your first lines. If it won't stay open and there are no errors, then it could be you have a problem not relating to the code. Possibly it could be your IDE or something, but it works fine for me.
are you compiling this under windows? if not system commands are not portable. you could try adding to the end to try and make it stay open. i dont think its your ide i think its your use of system.
Nope I did what Moschops and acorn said it still does not stay open:
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int iPlayers;
int iHours;
int iPoints;
int iGames;
int iaverage_player_hrs;
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;
int iaverage_player_hrs = iHours/iPlayers;
cout <<" The average player Hours are: " << iavarage_player_hrs << endl << endl;
int iaverage_player_points = iPoints/iPlayers;
cout <<" The average player points are: "<< iaverage_player_points<<endl<<endl;
int iaverage_points_game = iPoints/iGames;
cout <<" The average game points are: "<< 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 are: " << iaverage_points_per_hour_per_player << endl;
std::cin.sync();
std::getchar();
system("PAUSE");
return 0;
}
Also I am using Windows Vista, Visual C++ 2008 Express
Do you actually get to enter any data at all? When I try to compile you code as in your post before this one, I get the following errors and it does not compile, so I am astounded that it compiles for you.
bad3.cpp:36: error: redeclaration of ‘int iaverage_player_hrs’
bad3.cpp:18: error: ‘int iaverage_player_hrs’ previously declared here
bad3.cpp:38: error: ‘iavarage_player_hrs’ was not declared in this scope
bad3.cpp:54: error: ‘getchar’ is not a member of ‘std’
well your getting the not is a member of std because the standard namespace was already blown open because of using namespace std; he will have to remove the std:: prefix. i didnt check the other errors
well your getting the not is a member of std because the standard namespace was already blown open because of usingnamespace std; he will have to remove the std:: prefix.
It has nothing to do with already declaring usingnamespace std. getchar actually is not a member of std namespace.