Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

With the follwing text how would i displayed this text file into my c ++ program

ID: 3871353 • Letter: W

Question

With the follwing text how would i displayed this text file into my c ++ program. Also i need it to dispalyed with the cout screen as well as showing the sum of the total amount owed. The total amount owed for each order is listed but my program need to caclates the sum of the total amount owed. Also it shouldnt matter what file is used and need to displayed the total amount owed regardless of the file which means I cant just said cout << "the total of the sum is 50" << endl; because the total amount owed can be diffrent depending on the number on the file.

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 Pea

r Order: Frappuccino 67 oz

Price of Coffee: $15.91

Sales Tax: $1.10

Total Amount Owed: $12.08

Explanation / Answer

#include <bits/stdc++.h>
#include <fstream>

using namespace std;
int main()
{
   char filename[20];
   double total = 0.0;

   cout<<"Enter file Name:-";
   cin>>filename;

   ifstream file;
    file.open(filename);
  
    string str;
    int count = 0;
  

    while (getline(file, str))
    {
        cout<<str<<endl;
        if(str[0] == '' || str[0] == ' ')
           continue;
        count++;
        if(count == 5)
        {
           count = 0;
           int len = str.length();
           int i=0;
           while(str[i]!='$')
               i++;
           i++;
           string amount;
           while(str[i]=='.' || (str[i]<='9' && str[i] >= '0'))
               amount += str[i++];
           amount += '';
           // /cout<<amount<<endl;
           total += atof(amount.c_str());
           //cout<<"the total of the sum is-"<<total<<endl;

        }
    }
    cout<<"the total of the sum is-"<<total<<endl;
    return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote