mardi 2 janvier 2018

Generating random numbers not working

I am trying to make a program that generates random numbers. It takes the two numbers between which the random numbers have to be generated from the user. The logic behind the program is that there is an infinite loop which keeps on generating numbers. The moment the user enters 'a' the loop will stop and return the number. Here is the code:

#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int randnum(int, int);
int rand1(int);
int initial, final, randnum1;
cout<<"Type the inital value: ";
cin>>initial;
cout<<"Type the final value: ";
cin>>final;
cout<<"Enter a to generate random value";
randnum(initial, final);
rand1(randnum1);
getch();
return 0;
}
randnum(int initial, int final)
{
int randnum1;
randnum1=initial;
for( ; ; )
{
if(randnum1>final)
{
randnum1=initial;
}
return randnum1;
randnum1++;
}
}
rand1(int randnum1)
{
int a=97, num=0 ;
char a1;
for(int i=97 ; i!=num ;)
{
cin>>a1;
num=a1;
if(num==a)
{
cout<<randnum1;
}
}
}




Aucun commentaire:

Enregistrer un commentaire