Hi, can some one please have a look at my code for the user to enter integers and display it back to him.
For some reason my program can not accept more than 8 integers?
I wrote this program for a class assighnment where we where suppose to ask the user what size the array should be and of what type it should be and then he must enter the varaibles he requested in the array and it must be displayed back to him.
After stripping everything out to only this fixed int array I got the following error after entering the 9th integer: "The application was unable to start correctly (0xc0000142). Click OK to close the application."
Please help...

#include <iostream>

using namespace std;

int main()
{
  int intArray[100];
  int arrayPosition=0,userInput=0;
  
  cout<<"Enter 10 integers."<<endl;
  while(arrayPosition<10)
    {
    cin>>userInput;
    intArray[arrayPosition]=userInput;
    arrayPosition++;
    }
  arrayPosition=0;
  while(arrayPosition<10)
    {
    cout<<intArray[arrayPosition]<<" ";
    arrayPosition++;
    }
  return 0;
}

Thanks

It compiles and runs just fine for me...

Yes it compiles fine, but when I run it up to 8th integer it is fine but when I enter the 9th integer the app close and give me that error.
Could it be OS related? I resently upgraded to windows 7 from XP.

It ran all the way through when I ran it.

I suppose that an OS issue is possible, but if you haven't had any issue with other programs, I have my doubts. I tested on XP Pro SP3, I can't test on Win7 right now. It's on my other computer that I won't have access to until tomorrow.

Have you run any diagnostics on your system memory? It's possible you're running into some damaged memory locations.

You could save the code to a different file and try running it there ....

I have run the standerd windows memory diagnostics and it gave me no errors.
Wrote this program in 3 different files in different forms and got the same error...

What version of Windows? Is it 32-bit or 64-bit? What compiler and version? There's nothing wrong with your code, and I have heard of this error on Windows 7 before. Have you tried using compatibility mode, and does it still fail?

Windows 7 Home Basic 32-bit OS,
I am using MinGW not to sure where to check the version.
Found a lot of threads with this error but no compatibility mode solved any of them.
When I saved this codeunder a new name this was the last result I got from it:
Enter 10 integers.
1
2
3
4
5
6
7
8
1 2 3 4 5 6 7 8 8 8 Press any key to continue . . .
When I entered the 8 it gave the result with 8 in 9 and 10 as well :-)

>Found a lot of threads with this error but no compatibility mode solved any of them.
I don't care about them. Did it help your problem?

>When I saved this codeunder a new name this was the last result I got from it:
I'll assume you neglected to mention a ctrl+z after typing '8'. If that's the case, your output is expected.

Ok tried compatibility with XP sp3 and it did the same as original problem closing the window after I enter the 8th integer but without the error mesage this time.
No I did not use ctrl+z just the numeric keypad and the enter on the numeric keypad, and num lock is on.
Ok run this on a nother PC with windows 7 pro also only 32-bit and there it worked, this seems to be a Home edition proplem for me...

This won't solve your problem but to make the code shorter you could just have the input go straight to the array.

Instead of:
cin>>userInput
intArray[arrayPosition]=userInput;

Just go straight to:
cin>>intArray[arrayPosition];

Ok tried compatibility with XP sp3 and it did the same as original problem closing the window after I enter the 8th integer but without the error mesage this time.
No I did not use ctrl+z just the numeric keypad and the enter on the numeric keypad, and num lock is on.
Ok run this on a nother PC with windows 7 pro also only 32-bit and there it worked, this seems to be a Home edition proplem for me...

Did you compile it on your computer and transfer the *.exe to the other computer or did you compile it on the other computer then run it? I ask because if you did not, you have not eliminated a potential issue with your compiler as the cause of the problem.

Did you compile it on your computer and transfer the *.exe to the other computer or did you compile it on the other computer then run it? I ask because if you did not, you have not eliminated a potential issue with your compiler as the cause of the problem.

I copeyd the .exe file onto a memory stick and run it on the other PC, thinking of upgrading to home premium or 7 profesional not to sure what is the best option for me..

Thanks for the tip EpSilon92!
:-)

I copeyd the .exe file onto a memory stick and run it on the other PC, thinking of upgrading to home premium or 7 profesional not to sure what is the best option for me..

If you can, try compiling on the other PC. If the program does the same thing, it's most likely a code issue, otherwise, it's probably the result of platform and/or compiler glitches/differences. What are the hardware and software specifications on the 2 machines?

Hi Fbody, thanks for the effort, the other PC is a neighbors i do not no the stats myne is a upgrade done at a shop and all I know is there is an I3 cpu with 4Gig Ram and some sort of 1 Gig graphics card in. :-) realy not into the hardware side of PC's and just learning the software side...
Think I will close this thread now, thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.