Okay i have this problem with the output, it displays all off the random numbers in their array except for the last array. The last array is filled with pretty much nonsense. I have tried a few things but cannot get it to work. Another problem is the random numbers are the exact same every time i run the program, such as array 1 will be 22 and array 2 will be 56 every single time i run the program.
PHP Code:
/****************************************************
Random Lists - awlists.cpp
-----------------------------------------------------
Using 1D arrays and looping structures, display the
contents of an array filled with random numbers.
-----------------------------------------------------
Coded by: Andrew Weir
November 20th,2002
****************************************************/
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
#include<string.h>
#include<math.h>
#include<time.h>
#include<stdlib.h>
struct info
{
char userResponse;
//used to repeat the program
int iCounter, rowCounter, arrayNumber, arrayActual[30], arrayCounter, randomNumber;
//iCounter used for the loop in the outputForm function
//rowCounter used to make sure it prints 5 items per row
//arrayNumber used for the user input for amount of arrays
//arrayActual is the actual array holding the random numbers
//arrayCounter is used in the rndmProcedure function in the for loop
//randomNumber is used to generate the random numbers
string firstName, lastName, fullName;
};
info vars;
void fowlerStatement()
{
gotoxy(25,2);
cout<<"Random Lists";
gotoxy(25,3);
cout<<"~~~~~~~~~~~~";
gotoxy(5,5);
cout<<"This program will ask the user to input a number";
gotoxy(5,6);
cout<<"of arrays while the computer randomly fills each";
gotoxy(5,7);
cout<<" array with a random number.";
//gotoxy(5,8);
//cout<<" The number is between 1-10.";
gotoxy(5,10);
cout<<"This program was written in C++ by: Andrew Weir";
getch();
}
void inputForm(info& vars)
{
clrscr();
gotoxy(25,2);
cout<<"Random Lists";
gotoxy(25,3);
cout<<"~~~~~~~~~~~~";
gotoxy(5,5);
cout<<"Please enter your first name: ";
cin>>vars.firstName;
gotoxy(5,7);
cout<<"Please enter your last name: ";
cin>>vars.lastName;
vars.fullName = vars.lastName+", "+vars.firstName;
gotoxy(5,9);
cout<<"Please enter the amount of numbers to be generated: ";
cin>>vars.arrayNumber;
if(vars.arrayNumber>30)
{
do
{ gotoxy(42,10);
cout<<" ";
gotoxy(5,10);
cout<<"Please enter a number lower than 30: ";
cin>>vars.arrayNumber;
}
while(vars.arrayNumber>30);
}
}
void rndmProcedure(info& vars)
{
randomize;
for(vars.arrayCounter = 0; vars.arrayCounter != vars.arrayNumber; vars.arrayCounter++)
{
vars.randomNumber = random(99)+1;
vars.arrayActual[vars.arrayCounter] = vars.randomNumber;
}
}
void outputForm(info& vars)
{
clrscr();
/*gotoxy(1,1);
time_t t = time(NULL);
cout<<ctime(&t);
gotoxy(25,3);
cout<<"Random Lists";
gotoxy(25,4);
cout<<"~~~~~~~~~~~~";
gotoxy(5,6);
cout<<"Name of client: ";
cout<<vars.fullName;
gotoxy(40,6);
cout<<"Array # Limit: ";
cout<<vars.arrayNumber;*/
vars.rowCounter=0;
vars.iCounter=0;
do
{
vars.iCounter++;
vars.rowCounter++;
cout<<setiosflags(ios::right);
//if(vars.iCounter!=vars.arrayNumber)
//{
cout<<vars.arrayActual[vars.iCounter]<<" ";
//}
if(vars.rowCounter>=6)
{
cout<<endl;
vars.rowCounter=0;
}
}
while(vars.iCounter!=vars.arrayCounter);
getch();
//gotoxy(15,12);
//cout<<"-Thank You for using Random Lists-";
}
main()
{
info vars;
fowlerStatement();
do
{
inputForm(vars);
rndmProcedure(vars);
outputForm(vars);
gotoxy(15,14);
cout<<"Would you like to try agin (y/n): ";
cin>>vars.userResponse;
}
while(vars.userResponse=='y' || vars.userResponse=='Y');
}
Any help is greatly appreciated.