Create a program that saves prices in a sequential access file. Save the prices
ID: 3639620 • Letter: C
Question
Create a program that saves prices in a sequential access file. Save the prices in fixed-point notatio with two decimal places. Use a negative number as teh sentinel value. Save and then run the program. Enter the following prices an sentinel value: 10.50, 15.99, and -1. Now, run the program again. Thistime, enter the following pries and sentiel value: 20, 76.54, 17.34,and -1. Open the file in a text editor. The file should contan five prices, with each prices appearing on a seperate line in the file.Explanation / Answer
please rate - thanks
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
int main(){
double n;
ofstream out;
char filename[80];
cout<<"Enter file name: ";
cin>>filename;
out.open(filename,fstream::app);
cout<<"enter a number(-1 to exit): ";
cin>>n;
while(n!=-1)
{
out<<setprecision(2)<<fixed<<n<< endl;
cout<<"enter a number(-1 to exit): ";
cin>>n;
}
out.close();
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.