Program implementation(shipping charges)

Pages: 12
Yes, erase all that stuff in main... Now try and figure out how to read the info from the file.
Well I gave up. But still thx... So hard to program for me :(
I hope this helps you if you come up against similar problems:

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
49
50
51
52
53
54
55
#include <iostream>
#include <fstream>
#include <string>

int main()
{
    std::string str;
    int numPackages, packageType;
    double total, packageWeight, pricePerOunce1, pricePerOunce2;
    std::ifstream fin("input.txt");
    std::ofstream fout("output.txt");

    if (!fin)
    {
        std::cout << "Unable to open input file.";
        return 1;
    }
    fin >> numPackages;
    for (int i = 0; i < numPackages; ++i)
    {
        getline(fin, str); // 1. read name
        fout << str << '\n'; // write name
        getline(fin, str); // 2. read street address
        fout << str << '\n'; // write street address
        getline(fin, str); // 3. read city
        fout << str << ", "; // write city
        getline(fin, str); // 4. read state
        fout << str << ' '; // write state
        getline(fin, str); // 5. read zip code
        fout << str << '\n'; // write zip code
        fin >> packageType;
        switch (packageType)
        {
            case 1: //overnight
                    //read other numbers
                    //calculate total
                    break;
            case 2: //two-day
                    //read other numbers
                    //calculate total
                    break;
            case 2: //ground
                    //read other numbers
                    //calculate total
                    break;
        }
        fout << total << '\n';
        fin.ignore(); //ignore rest of numbers line
        fin.ignore(); //ignore empty line
    }
    fin.close();
    fout.close();

    return 0;
}
Last edited on
Topic archived. No new replies allowed.
Pages: 12