i want my random number genereted on the selection bases of vowel or consonent, should be stored in a file permanently on hard disk the below code creates a file but does not store any thing, what should i do? i tried in different ways like without using global variable "f" or declaring the file opening code in both the functions independently insted of a single code in main but all that did not work, file is created but nothing stored.
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<fstream.h>
int hun();
int thou();
char f;
int main()
{
char in,x;
{
cout<<endl<<"Please enter the alphabet"<<endl;
cin>>in;
x=in;
if (x=='a'||x=='e'||x=='i'||x=='o'||x=='u')
{
hun();
}
else
{
thou();
}
ofstream out;
out.open("D:\\alphabet.txt");
if(!out)
{
cout<<"Error opening file";
}
else
{
exit(1);
}
out<<f;
out.close();
}
}
int hun()
{ int seed;
seed=4;
srand(seed);
for(int i=1; i<2; i++)
{
int res1=rand()%((100+1)-(1))+1;
f=res1;
cout<<" "<<res1;
if(i%2==0)
{
break;
}
}
return f;
}
int thou()
{ int seed;
seed=10;
srand(seed);
for(int i=1; i<2; i++)
{
int res2=rand()%((2000+1)-(1000))+1000;
f=res2;
cout<<" "<<res2;
if(i%2==0)
{
break;
}
}
return f;
}