some help please

Write a program that displays the contents of a file in four columns titled “Item Name”, “Num of
Items”, “Item Price”, “Total”. The total is the is the quantity of each item sold multiplied by the
item price. This program should not use an array. However, it should read all values from file
named “itemFile.txt”, perform calculations where possible, and display everything in the
C++ output window. The program should also calculate the total price of all items sold. Copy the
contents of your file and paste them below your program. Submit your program together with the
output.
Don't double post.

You didn't ask a question, you just copied your PDF's assignment text.
What are you having trouble with? Show us what you've tried.
to be honest with you i don't know how to start first, I'm still learning the topic and surprise me with the assignment that I have to submit it today. i need help with the code so then it can help me to have an idea
Hello shokoro10,

Start with providing the input file, so that everyone will know what you have to read and can use the same information.

Next, start with:

Write a program that displays the contents of a file in four columns titled “Item Name”, “Num of
Items”, “Item Price”,


That is simple enough. A program that outputs the headings. Then start with reading one record. When that works expand it to a loop to read the entire file.

Once you have it that far doing the totals is easy to add.

Andy
can see some code so then to have an idea
Hello shokoro10,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <cctype>
#include <iostream>
#include <iomanip>
#include <string>
#include <limits>

#include <fstream>

int main()
{
    const std::string inFileName{ "Answer.txt" };

    std::ifstream inFile(inFileName);

    if (!inFile)
    {
        std::cout << "\n File " << std::quoted(inFileName) << " did not open" << std::endl;

        return 1;
    }

    std::cout << "\n Do you want someone to do all the work for you? ";

    std::string line;
    char answer{};
    std::cin >> answer;

    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');

    if (std::toupper(answer) == 'Y')
    {
        while (std::getline(inFile, line))
        {
             std::cout << ' ' << line << '\n';
        }

        std::cout << "\n Else post it in the Jobs section.\n";
    }

    else
    {
        std::cout << "Show what you have coded so far.\n";
    }

    std::cout << "Good luck.\n";

    return 0;
}


Andy
thank you i got the idea
Topic archived. No new replies allowed.