| View previous topic :: View next topic |
| Author |
Message |
Kipodimkozim Advanced Cheater
Reputation: 0
Joined: 05 Oct 2008 Posts: 94 Location: Inside your head
|
Posted: Fri Jan 02, 2009 3:59 pm Post subject: [c++] Weird error when executing a file |
|
|
Hey guys,
When compiling this code (homework I got) I get no error and the code compiles smoothly but when I'm executing the exe file I'm getting this error from vista:
Problem signature:
Problem Event Name: APPCRASH
Application Name: Grade.exe
Application Version: 0.0.0.0
Application Timestamp: 495e8a74
Fault Module Name: Grade.exe
Fault Module Version: 0.0.0.0
Fault Module Timestamp: 495e8a74
Exception Code: c0000005
Exception Offset: 000267ec
OS Version: 6.0.6001.2.1.0.768.3
Locale ID: 1037
Additional Information 1: 026b
Additional Information 2: 2b7432bc90ed02e22ca41bcd76a0c865
Additional Information 3: 7dd6
Additional Information 4: 51623fa4f0f94975881aaf6bdad2573f
The code:
| Code: | #include <iostream>
#include <stdio.h>
using namespace std;
const MAXGRADE = 10;
int main()
{
system("TITLE What's my GPA");
double grades[MAXGRADE];
int numgrade;
double average, total;
cout << "What's my GPA:" << endl;
cout << "--------------" << endl << endl;
for(numgrade = 1; numgrade <= MAXGRADE; numgrade++){
cout << "Enter the " << numgrade << "Th grade: " << endl;
cin >> grades[numgrade];
}
// הצגת הציונים
cout << endl << "The grades are:" <<endl;
cout << "---------------" << endl;
for(numgrade = 1; numgrade <= MAXGRADE; numgrade++){
cout << "The " << numgrade << "Th grade is: " << std::dec << grades[numgrade] <<
endl;
}
// חישוב ההמוצע והצגתו
total = 0;
for(numgrade = 1; numgrade <=MAXGRADE; numgrade++){
total += grades[numgrade];
}
average = (total) / MAXGRADE;
cout << endl << "The average grade is: " << std::dec << average << endl << endl;
getchar();
return 0;
} |
Is it a problem with the code I wrote or something with my computer?
_________________
My smexy priest soon to be bishop:
[ ] Lvl 70
[ ] Lvl 100
[X] Lvl 120
[x] Genesis
[x] Zhelm
[ ] HT Pendant
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Learning C++ |
|
| Back to top |
|
 |
Heartless I post too much
Reputation: 0
Joined: 03 Dec 2006 Posts: 2436
|
Posted: Fri Jan 02, 2009 4:28 pm Post subject: |
|
|
| Code: | | const MAXGRADE = 10; |
No type
| Code: | | // חישוב ההמוצע והצגתו |
try taking these characters out
Other than the first one, works fine one WindowsXP.
_________________
What dosen't kill you, usually does the second time. |
|
| Back to top |
|
 |
Kipodimkozim Advanced Cheater
Reputation: 0
Joined: 05 Oct 2008 Posts: 94 Location: Inside your head
|
Posted: Fri Jan 02, 2009 4:40 pm Post subject: |
|
|
| HornyAZNBoy wrote: | | Code: | | const MAXGRADE = 10; |
No type
| Code: | | // חישוב ההמוצע והצגתו |
try taking these characters out
Other than the first one, works fine one WindowsXP. |
Oh lol I haven't noticed that I haven't assigned any type o.O
EDIT: I'm still getting the same mistake even tho I've changed the const type, I don't get any error when compiling so I guess it's my computer..
_________________
My smexy priest soon to be bishop:
[ ] Lvl 70
[ ] Lvl 100
[X] Lvl 120
[x] Genesis
[x] Zhelm
[ ] HT Pendant
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Learning C++ |
|
| Back to top |
|
 |
masterzero Expert Cheater
Reputation: 1
Joined: 09 Nov 2008 Posts: 137
|
Posted: Fri Jan 02, 2009 4:54 pm Post subject: |
|
|
| it might be your compiler which one are you using
|
|
| Back to top |
|
 |
sloppy Expert Cheater
Reputation: 0
Joined: 17 Aug 2008 Posts: 123
|
Posted: Fri Jan 02, 2009 5:04 pm Post subject: |
|
|
| (C++) Array elements start at zero, grades[10] has a range of 0-9. Your for loop is going outside these bounds. Begin your loops from 0 or use numgrade-1 when accessing the array.
|
|
| Back to top |
|
 |
Kipodimkozim Advanced Cheater
Reputation: 0
Joined: 05 Oct 2008 Posts: 94 Location: Inside your head
|
Posted: Fri Jan 02, 2009 5:17 pm Post subject: |
|
|
| masterzero wrote: | | it might be your compiler which one are you using |
Visual C++ 6.0
_________________
My smexy priest soon to be bishop:
[ ] Lvl 70
[ ] Lvl 100
[X] Lvl 120
[x] Genesis
[x] Zhelm
[ ] HT Pendant
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Learning C++ |
|
| Back to top |
|
 |
Heartless I post too much
Reputation: 0
Joined: 03 Dec 2006 Posts: 2436
|
Posted: Fri Jan 02, 2009 5:18 pm Post subject: |
|
|
Maybe it is your settings, or vista.
_________________
What dosen't kill you, usually does the second time. |
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Fri Jan 02, 2009 5:58 pm Post subject: |
|
|
look carefully at your loops, and watch very carefully how 'grades' is filled.
you are going out of bounds in your array.
edit: god dammit sloppy beat me.
|
|
| Back to top |
|
 |
rapion124 Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Mar 2007 Posts: 1095
|
Posted: Fri Jan 02, 2009 6:40 pm Post subject: |
|
|
Maybe if you looked up the exception code, you would notice that C0000005 means an access violation.
Change
| Code: |
for(numgrade = 1; numgrade <= MAXGRADE; numgrade++)
|
to
| Code: |
for (numgrade = 1; numgrade [b]<[/b] MAXGRADE; numgrade++)
|
[/code]
|
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Fri Jan 02, 2009 10:07 pm Post subject: |
|
|
| rapion124 wrote: | Maybe if you looked up the exception code, you would notice that C0000005 means an access violation.
Change
| Code: |
for(numgrade = 1; numgrade <= MAXGRADE; numgrade++)
|
to
| Code: |
for (numgrade = 1; numgrade [b]<[/b] MAXGRADE; numgrade++)
|
[/code] |
That would skip the first grade.
| Code: |
for( numgrade = 0; numgrade < MAXGRADE; numgrade++ )
|
or
| Code: |
for( numgrade = 1; numgrade <= MAXGRADE; numgrade++ ) {
std::cin >> grades[ numgrade - 1 ];
}
|
_________________
|
|
| Back to top |
|
 |
Kipodimkozim Advanced Cheater
Reputation: 0
Joined: 05 Oct 2008 Posts: 94 Location: Inside your head
|
|
| Back to top |
|
 |
|