hi,
i have a txt file "names" containing 300 set of personal info such as:
3765 // id
thomas //last name
barry // first name
876-988776 //phone number
16.37 // a price of what he purchased
8765 // id repeat
dionisio // last name repeat
tom // first name repeat
..... // and so on ...
i am trying to read them into array and cout them in a backward order... however, it stopped displaying content in around the middle... Any body please tell me why.. thanks
# include <iostream>
# include <fstream>
# include <cstdlib>
# include <string>
using namespace std;
int main()
{
int id[300];
string lastName[300];
string firstName[300];
string phone[300];
double amount[300];
ifstream reader;
reader.open("names.txt");
int i=0;
while(reader>> id[i] >> lastName[i] >> firstName[i] >> phone[i] >> amount[i])
{
i++;
}
//total number is known as i
int x = i-1;
for(x; x>-1; x--)
{
cout<<id[x]<<endl;
cout<<lastName[x]<<endl;
cout<<firstName[x]<<endl;
cout<<phone[x]<<endl;
cout<<amount[x]<<endl;
}
reader.close();
return 0;
}