This is my homework. How would I transfer/ read this file name coffeesaver.txt i
ID: 3887480 • Letter: T
Question
This is my homework. How would I transfer/ read this file name coffeesaver.txt into c ++? I need the user when it is displayed to see it on the cout menu as well.
David Moore
Order: Plain Coffee 14 oz
Price of Coffee: $1.52
Sales Tax: $0.12
Total Amount Owed: $1.81
Ran Willy
Order: Latte 23 oz
Price of Coffee: $6.44
Sales Tax: $0.45
Total Amount Owed: $6.89
Lord Varvin
Order: Plain Coffee 34 oz
Price of Coffee: $4.42
Sales Tax: $0.31
Total Amount Owed: $4.73
Scary Sherlock
Order: Macchiato 15 oz
Price of Coffee: $3.75
Sales Tax: $0.26
Total Amount Owed: $4.01
Harry Pear
Order: Frappuccino 67 oz
Price of Coffee: $15.91
Sales Tax: $1.10
Total Amount Owed: $12.08
Explanation / Answer
Hi Let me know if you need more information:-
======================================
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
string line;
ifstream file("coffeesaver.txt");
if (file.is_open()) {
while (getline(file, line)) {
cout << line << ' ';
}
file.close();
}
else{
cout << "can't open file";
}
return 0;
}
====
INPUT:-
======
coffeesaver.txt
==============
David Moore
Order: Plain Coffee 14 oz
Price of Coffee: $1.52
Sales Tax: $0.12
Total Amount Owed: $1.81
Ran Willy
Order: Latte 23 oz
Price of Coffee: $6.44
Sales Tax: $0.45
Total Amount Owed: $6.89
Lord Varvin
Order: Plain Coffee 34 oz
Price of Coffee: $4.42
Sales Tax: $0.31
Total Amount Owed: $4.73
Scary Sherlock
Order: Macchiato 15 oz
Price of Coffee: $3.75
Sales Tax: $0.26
Total Amount Owed: $4.01
Harry Pear
Order: Frappuccino 67 oz
Price of Coffee: $15.91
Sales Tax: $1.10
Total Amount Owed: $12.08
=====================================
Thanks
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.