Okay that didnt really work. It just gave out some wierd numbers that came outta nowehre. Im not sure if it was what i did with it when i put it into my program or if u made a mistake but could you take a quick look at my code and see if can find the problem?
thanx in advance
Code:
/****************************************************
Class Statistics - awclass.cpp
-----------------------------------------------------
Using 1D arrays and looping structures, determine the
failing status of a mark and display the statistics
summary
-----------------------------------------------------
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, studentsFailed, studentsPassed, arrayNumber;
int arrayActual[30], arrayCounter, randomNumber;
int offset, maxval;
//iCounter used for the loop in the outputForm function
//studentsFailed is to count the amount of failing students
//studentPasses is to count the amount of passing students
//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<<"Class Statistics";
gotoxy(25,3);
cout<<"~~~~~~~~~~~~~~~~";
gotoxy(5,5);
cout<<"This program will ask the user to input the number";
gotoxy(5,6);
cout<<"of students in a class while the computer randomly gives";
gotoxy(5,7);
cout<<" each student a mark.";
gotoxy(5,10);
cout<<"This program was written in C++ by: Andrew Weir";
getch();
}
void inputForm(info& vars)
{
clrscr();
gotoxy(25,2);
cout<<"Class Statistics";
gotoxy(25,3);
cout<<"~~~~~~~~~~~~~~~~";
gotoxy(5,5);
cout<<"Please enter teacher's first name: ";
cin>>vars.firstName;
gotoxy(5,7);
cout<<"Please enter teacher's last name: ";
cin>>vars.lastName;
vars.fullName = vars.lastName+", "+vars.firstName;
gotoxy(5,9);
cout<<"Please enter the amount of students in the class: ";
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;
vars.studentsFailed=0;
vars.studentsPassed=0;
for(vars.arrayCounter = 0; vars.arrayCounter != vars.arrayNumber; vars.arrayCounter++)
{
vars.randomNumber = random(99)+1;
vars.arrayActual[vars.arrayCounter] = vars.randomNumber;
}
vars.iCounter=0;
while(vars.iCounter < vars.arrayCounter)
{
vars.iCounter++;
if(vars.arrayActual[vars.iCounter] >=50)
{
vars.studentsPassed++;
}
if(vars.arrayActual[vars.iCounter] <50)
{
vars.studentsFailed++;
}
}
}
void outputForm(info& vars)
{
clrscr();
##################PROBLEM#####################
*********************************************/
for (int i = 0; i < 32; i++)
{
if (vars.arrayActual[i] > vars.maxval)
{
vars.offset = i;
vars.maxval = vars.arrayActual[i];
}
}
/***********************************************
gotoxy(1,1);
time_t t = time(NULL);
cout<<ctime(&t);
gotoxy(25,3);
cout<<"Class Statistics";
gotoxy(25,4);
cout<<"~~~~~~~~~~~~~~~~";
gotoxy(5,6);
cout<<"Name of client: ";
cout<<vars.fullName;
gotoxy(40,6);
cout<<"Class Size: ";
cout<<vars.arrayNumber;
cout<<setiosflags(ios::right);
gotoxy(5,8);
cout<<"Number of failing students.................: ";
cout<<setw(3)<<vars.studentsFailed;
gotoxy(5,9);
cout<<"Number of passing students.................: ";
cout<<setw(3)<<vars.studentsPassed;
gotoxy(5,10);
cout<<"Student number "<<vars.offset<<" obtained a mark of.......: ";
cout<<setw(3)<<vars.maxval;
gotoxy(15,14);
cout<<"-Thank You for using Class Statistics-";
}
main()
{
srand(time(NULL));
info vars;
fowlerStatement();
do
{
inputForm(vars);
rndmProcedure(vars);
outputForm(vars);
gotoxy(15,15);
cout<<"Would you like to try again (y/n): ";
cin>>vars.userResponse;
}
while(vars.userResponse=='y' || vars.userResponse=='Y');
}
*/