I am writing a program to have the user enter numbers which will in turn be placed in an array. This array will then be printed on the screen I am using a For loop for both, but the program seems to skip some lines of code and not others. Here is the code:
#include "stdafx.h"
#include "math.h"
using namespace System;
int main(array<System::String ^> ^args)
{
int i; // variable for tracking for loops
int a; // variable to enter into array
int count; //Track array data
int array1[5]; //Define array
for(i=0;i<6;i++) // build array
{
Console::WriteLine("Enter a number:");
a=Console::Read();//user input
a=array1[count]; // place user input into array
count++;
}
for(i=0;i<6;i++) // display array
{
Console::WriteLine(array1[i]);
}
Console::WriteLine("Press enter to close"); // close program
Console::Read();
return 0;
}
Enter a number: <- all seems good here
1
Enter a number: <- These three lines print out immediatly and don't allow me to
Enter a number: input anything
Enter a number:
2 <- Program allows me to enter another number
Enter a number: <- Last two lines are printed immediatly
Enter a number:
5246767 <-The output is random, but I expected that as I am not using
657 pointers yet. My real problem is with the for loop.
0
25645
4577
Press enter to close
Is this a coding error or logic problem? Any help is appreciated.