Okay in this vector array program I got it to print out the values in the input file number and price. How would i go about havng a question in the bottom somewhere asking a user for an item number , meaning first - 10 entrys in the input file.
for example here is my txt file.
100 13.43
101 10.99
102 3.45 (lets say i want the user to be able to type a number
of 3 and it will go and display this info.)
103 5.72
104 6.90
105 3.99
106 2.78
107 15.98
108 4.34
109 2.87
110 3.67
Here is my code so far:
Code:#include <iostream> #include <vector> #include <fstream> #include <iomanip> using namespace std; void main() { vector<int> number; vector<double> price; int num; double pri; ifstream inFile("product.txt", ios::in); if(!inFile) { cerr<<"File could not be opened!"<<endl; exit(1); } while(!inFile.eof()) { inFile >> num >> pri; number.push_back(num); price.push_back(pri); } cout << setw(10)<< "Product no." << setw(10) << "Price" << "\n"; for(int i=0; i < number.size(); i++) cout << setw(10) << number[i] << setw(10) << price[i] << "\n"; }