Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[c++] Weird error when executing a file

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Kipodimkozim
Advanced Cheater
Reputation: 0

Joined: 05 Oct 2008
Posts: 94
Location: Inside your head

PostPosted: Fri Jan 02, 2009 3:59 pm    Post subject: [c++] Weird error when executing a file Reply with quote

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
View user's profile Send private message
Heartless
I post too much
Reputation: 0

Joined: 03 Dec 2006
Posts: 2436

PostPosted: Fri Jan 02, 2009 4:28 pm    Post subject: Reply with quote

Code:
const MAXGRADE = 10;

No type

Code:
// הצגת הציונים

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
View user's profile Send private message
Kipodimkozim
Advanced Cheater
Reputation: 0

Joined: 05 Oct 2008
Posts: 94
Location: Inside your head

PostPosted: Fri Jan 02, 2009 4:40 pm    Post subject: Reply with quote

HornyAZNBoy wrote:
Code:
const MAXGRADE = 10;

No type

Code:
// הצגת הציונים

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
View user's profile Send private message
masterzero
Expert Cheater
Reputation: 1

Joined: 09 Nov 2008
Posts: 137

PostPosted: Fri Jan 02, 2009 4:54 pm    Post subject: Reply with quote

it might be your compiler which one are you using
Back to top
View user's profile Send private message
sloppy
Expert Cheater
Reputation: 0

Joined: 17 Aug 2008
Posts: 123

PostPosted: Fri Jan 02, 2009 5:04 pm    Post subject: Reply with quote

(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
View user's profile Send private message
Kipodimkozim
Advanced Cheater
Reputation: 0

Joined: 05 Oct 2008
Posts: 94
Location: Inside your head

PostPosted: Fri Jan 02, 2009 5:17 pm    Post subject: Reply with quote

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
View user's profile Send private message
Heartless
I post too much
Reputation: 0

Joined: 03 Dec 2006
Posts: 2436

PostPosted: Fri Jan 02, 2009 5:18 pm    Post subject: Reply with quote

Maybe it is your settings, or vista.
_________________
What dosen't kill you, usually does the second time.
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Fri Jan 02, 2009 5:58 pm    Post subject: Reply with quote

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
View user's profile Send private message
rapion124
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Mar 2007
Posts: 1095

PostPosted: Fri Jan 02, 2009 6:40 pm    Post subject: Reply with quote

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
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Fri Jan 02, 2009 10:07 pm    Post subject: Reply with quote

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 ];
}

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
Kipodimkozim
Advanced Cheater
Reputation: 0

Joined: 05 Oct 2008
Posts: 94
Location: Inside your head

PostPosted: Sat Jan 03, 2009 6:27 am    Post subject: Reply with quote

Thanks guys it worked! Very Happy
_________________
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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites