Hey Guys,
i'm new to the forum and I would appreciate any help.
I'm writing a program where the user needs to choose 5 numbers from 56. At the same time I'm using loop screen out numbers outside of this range.
As a result only the 1st number out of 5 is written into file. Where's the mistake?
#include <iostream>
#include <cstdlib>
#include<iomanip>
#include<fstream>
using namespace std;
int main()
{
int pick[5]={0};
ofstream outputfile;
bool correct = false;
int index=0;
do
{
cout <<"Please,enter the number in the range of 1 to 56\n"<<endl;
for(;index<5;)
{
cout<<" Enter number "<< index+1<<" out of 5:";
cin>> pick[index];
if (pick[index]<56)
{
outputfile.open("savednumbers.txt");
outputfile<<pick[index]<<endl;
outputfile.close();
correct=true;
index++;
}
else
{
cout << "You choice is outside of the range.\n Please choose number from 1 to 56.\n";
}
}
}
while( !correct );
cin.clear();
cin.ignore();
cin.get();
}