Using a while loop, write a C++ program that prompts the user to enter five numbers. As each number is entered the program should write the number into a file named user.txt Using a while loop, write a C++ program that reads the data in the user.txt file created above and displays each individual data item
1
Expert's answer
2013-04-09T09:13:39-0400
#include <fstream>
#include <iostream> using namespace std;
int main(int argc, char* argv[]) { double a[5]; ofstream fout("user.txt"); int i=0; while(i<5){ cin>>a[i]; fout <<a[i]<<endl; i++; } fout.close();
char buff[50]; ifstream fin("user.txt"); int j=0; while(j<5){ fin >> buff; cout << buff << endl; j++; & } fin.close(); int kl; cin>>kl; return 0; }
Comments
Leave a comment