Apr 28, 2008 at 1:18pm UTC
I was wondering if you can add random numbers
//-STD-----------------------------------------------------------------------
#include <vcl.h>
#include <cstring>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <iostream.h>
#include <ctime>
//---------------------------------------------------------------------------
void GetRndNum ();
//-----Declare Global Variables----------------------------------------------
int rndNum = 0;
int usrInp = 0;
int counter = 0;
/* Colors and Numbers
#define BLACK 0
#define BLUE 1
#define GREEN 2
#define CYAN 3
#define RED 4
#define MAGENTA 5
#define BROWN 6
#define LIGHTGREY 7
#define DARKGREY 8
#define LIGHTBLUE 9
#define LIGHTGREEN 10
#define LIGHTCYAN 11
#define LIGHTRED 12
#define LIGHTMAGENTA 13
#define YELLOW 14
#define WHITE 15
#define BLINK 128
*/
//---------------------------------------------------------------------------
#pragma argsused
int main(int argc, char* argv[]){
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), GREEN);
cout <<"HiLo Game"<<endl;
cout <<"========="<<endl;
while(1==1){
cout << " " << endl;
cout << "Enter a number" << endl;
cout << " " << endl;
cin >>usrInp;
cout << " " << endl;
cout<<"Random Numbers "<< endl;
cout<<"============== "<< endl;
srand((unsigned)time(NULL));
rndNum = rand() % 100;
for (int i = 0;i < usrInp ; i++){
rndNum = rand() % 100;
cout << rndNum<< " ";
}
counter ++;
}
getch();
return 0 ;
}
//---------------------------------------------------------------------------
Is there a way to add the total of all the random numbers when the user imputs a number?
Apr 28, 2008 at 5:01pm UTC
Dont really know what you are asking but looking at the source I think you are trying to make the user set the amount of loops to to make and total the random numbers, this may do the trick.
1 2 3 4 5 6 7 8 9 10 11
int RandFunction (int usrInp)
{
int temp
int temp2
for (i = 0; i < usrInp ; i++)
{
temp = rand() % 100;
temp2 = temp + temp2;
}
return temp2;
}
This function should do the trick, but I am fairly new to c++ so I am VERY error prone, just look over the code to see if its error free.
Last edited on Apr 28, 2008 at 5:01pm UTC