Hello. Let's start with my code:
When writing my "Example.txt" I want to make ALL seven numbers appear. But with this code only the last random number appears.Code:#include <stdio.h>
#include <fstream>
#include <iostream>
using namespace std;
void myflush(std::istream& in)
{
in.clear();
in.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}
void mypause()
{
myflush(std::cin);
std::cin.get();
}
int main(void)
{
char str[10];
srand((unsigned)time(0));
int random_integer;
for(int index=0; index<7; index++){
random_integer = (rand()%99)+1;
if (index) cout << ", ";
cout << random_integer;
}
cout << endl;
ofstream a_file ( "example.txt" );
a_file << random_integer;
a_file.close();
mypause();
}