My command prompt will not stay open

Pages: 12
i thought it was. if i type std:: in my compiler getchar() comes up as a possible match plus i get no errors..oh well live and learn. im using vc express 2010. that annoys me a little.


Looking at it, I can't be sure if it's meant to be or not. Some implementations do have it in std:: namespace, some don't...

I'll check the authority. I trusted the compiler I'm using (g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3) when it produced that error message, but to be honest it's as likely to be non-standard as the MS C++ compiler.

error C2086: 'int iaverage_player_hrs ' : redefinition


When you write int iaverage_player_hrs you're trying to create a new variable called iaverage_player_hrs. If you already have one, it won't work.

'iavarage_player_hrs' : undeclared identifier

This means that you have never created anything called iavarage_player_hrs . Looknig at your code, I can see that this is true; you have not created this variable anywhere.


Last edited on
Run-Time Check Failure #3 - The variable 'iavarage_player_hrs' is being used without being initialized.


This means that you are using the value of a variable called iavarage_player_hrs but you have never actually set it to equal anything, so there could be any value in there.

As an aside, average is spelled with an "e" after the "v".
Last edited on
moschops your right its not in the namespace std. it says if it is next to the tooltip when it suggests it. but if its not why suggest it in the first place. plus why no errors. i can blame intellesense on mixing up std and non standard but the compiling when its not kinda annoys me.
This means that you are using the value of a variable called iavarage_player_hrs but you have never actually set it to equal anything, so there could be any value in there.

As an aside, average is spelled with an "e" after the "v".


How do I fix this?

Also thank you for the typo. . . .
You fix it by correcting iavarage_player_hrs to the variable you actually are declaring, iaverage_player_hrs
int iaverage_player_hours; should be int iaverage_player_hours = 0;
Alright I have fixed I think:

#include <iostream>

#include <cstdlib>

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;

int iaverage_player_hrs = iHours/iPlayers;

cout <<" The average player Hours are: " << iaverage_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;

}

no, acorn... Moschops is correct. The mistake is in the spelling. Search for "iavarage_player_hrs" and change the second 'a' to an 'e'...
man i suck today. i just go hide under a tree somewhere
man i suck today. i just go hide under a tree somewhere


Haha you aided me in fixing my sad little novice program.

Thank you acorn and forum. ^_^
Last edited on
Man, You had some serious issues. From the looks of your compiler's output, I'd say you're using MSVC++.

You didn't have a semicolon after a variable, you were using system pause, you defined a variable twice, you misspelled a variable. Jeez.

Use Code::Blocks, it's much more versatile and descriptive when finding errors.

I ran the new and improved code and had a successful run. Code and output below.

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
58
//Code tested on Linux!

#include <iostream>

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;

iaverage_player_hrs = iHours/iPlayers;

cout <<" The average player Hours are: " << iaverage_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;

cin.get(); //this should fix your winblows problem

return 0;

}



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Enter in The Total Number of Players: 
5
Enter in The Total Number of Hours Played: 
50
Enter in The Total Number of Points Scored: 
500
Enter in The Total Number of Games Played: 
5
 The average player Hours are: 10

 The average player points are: 100

 The average game points are: 100

 The average points per hour per player are: 10
nope, not fixed... still need to clean up the code and put
[code]
[/code]
around the code. Oh, and stop using system() and using namespace std;... ;p


take off the std:: in front of getchar(); and add

#include <stdio.h>

to the top

.. or you can use cin.get(); ...
Last edited on
oh... I'm guessing dividing by zero wouldn't be good either

.. enter zero for all the fields and see what happens
Last edited on
The purpose of the program is to learn how things work and understand the fundamentals of C++. If this was meant to be 100% professional and absolutely perfectly working code, then I suspect he wouldn't be on these forums asking questions. Please, do use your brain when assisting the less-informed.
lol, I was having fun with the first part, hence the
;p
.. but dividing by zero is a problem
Topic archived. No new replies allowed.
Pages: 12