Beginners Assignment

Hello

I have been assigned the task of creating a C++ program for my CS221 course...

It needs to calculate the electricity bill for customers, based on the information placed in a premade input file, and place results in an output file.

After reading from the input file, I have developed, based on the outlines provided in the assignment, that this is the proper logic to follow:

Keep in mind, there are three ways to bill a customer, based on if they are a Residential (R) Senior (S) or Commercial (C)


Step 1
Determine usage
readingCurrent – readingPrevious = usage
UNLESS
The meter has rolled, then
100000.0 – readingPrevious = usage

Step 2
Determine the bill
For R
If usage is less than or equal to 300 kwh, bill = .09 * usage
If usage is between 300 and 600 kwh, bill = (.09*300) + (.08 * (usage-300))
If usage is between 400 and 1000 kwh, bill = (.09*300) + (.08 * 100) + (.06 (usage – 400))
If usage is above 1000, bill = (.09*300) + (.08 * 100) + (.06*600) + (.05(usage-1000))
For S
If usage is equal to or less than 500, bill = .085 * usage
If usage is above 500, bill = (.085 * 500) + (.07(usage – 500))
For C
If usage is less than or equal to 1000, bill = .075*usage
If usage is between 1000 and 1500, bill = (1000*.075) + (.065*(usage-1000))
If usage is above 1500, bill = (1000 * .075)+(.065*500)+(.045*(usage-1500))

Step 3
Add bill to total
Total bill = totalBill + bill
Total usage = totalUsage + usage



This is what I have so far, in my cpp file:

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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cwchar>
#include <cmath> 

using namespace std;

int main()
{
	ifstream inputFile;
	
	int rTier1, rTier2, rTier3, rTier4;
	int	sTier1, sTier2;
	int	cTier1, cTier2, cTier3;
	int account;
	double readingPrevious, readingCurrent, usage, bill, totalUsage, totalBill; 
	char customer[21], type, R, S, C;

	inputFile.open("C:\\Users\\Nathan Chesebro\\Documents\\Lake Superior State University\\Student\\CSCI121\\Assignment 4\\Assign4.txt");

	if (!inputFile)
		cout << "File Error.";

	else
	{
		while (!inputFile.eof())
		{

		inputFile >> account;
		inputFile >> customer; 
		inputFile >> readingPrevious >> readingCurrent >> type;
		
		{
			usage = readingCurrent - readingPrevious;
			//UNLESS the meter rolled
			usage = 100000.0 - readingPrevious;

			if(type = R)
			{
				if(usage <= 300)
				{
					bill = usage * .09;
				}

				while (300 < usage < 600);
				{
					bill = (.09 * 300) + (.08 * ( usage - 300 ) );
				}
				
				while (400 < usage < 1000);
				{
					bill = (.09 * 300) + (.08 * 100) + (.06 * (usage - 400)); 
				}

				while (1000 <= usage);
				{
					(.09 * 300) + (.08 * 100) + (.06 + 600) + (.05 * (usage - 1000)); 
				}
			}
			while (type = S)
			{
				if(usage <= 500)
				{
					bill = .085 * usage; 
				}
				while(usage > 500)
				{
					bill = (.085 * usage) + (.07 * (usage - 1000));
				}
			}
			while (type = C)
			{
				if(usage <= 1000)
				{
					bill = (.075 * usage); 
				}
				while (1000 < usage < 1500)
				{
					bill = (1000*.075) + (.065*(usage-1000));
				}
				while (usage > 1500)
				{
					bill = (1000 * .075)+(.065*500)+(.045*(usage-1500));
				}
			}
		}
	
		totalUsage = totalUsage + usage; 
		totalBill = totalBill + bill;

		ofstream outputFile;
		outputFile.open("billing.txt");
		outputFile << left << setw(10) << "Account   " << right << setw(20) << "Customer               " << right << setw(13) << "Type         " << right << setw(11) << "Current    " << right << setw(11) << "Previous   " << right << setw(8) << "Usage   " << right << setw(9) << "Bill     " << endl;
		outputFile << left << setw(10) << "-------   " << right << setw(20) << "--------------------   " << right << setw(13) << "----------   " << right << setw(11) << "--------   " << right << setw(11) << "--------   " << right << setw(8) << "-----   " << right << setw(9) << "-------- " << endl;
		outputFile << left << setw(10) << account      << right << setw(20) << customer                  << right << setw(13) << type            << right << setw(11) << readingCurrent<< right << setw(11) <<readingPrevious<< right << setw(8) << usage      << right << setw(9) << bill        << endl;
		outputFile << left << "Total Usage:   "        << totalUsage        << endl; 
		outputFile << left << "Total Billing: "        << totalBill         << endl;

		outputFile.close();
		return 0;
	}
}


I dont think i have the program set up correctly at all here... any pointers as to first, correctly read the input file (which is saved in the same folder as the cpp file) and correctly produce the output file (hopefully in the same location as the input)

The output file should have all the records listed, as well as a total usage and total consumption. The output file should also have as the first line, a title such as "This months customers"

What do I need to do to fix this mess?
well, for starters, you're missing a " } " at the end of your code. After adding it, the code compiled and linked just fine. I can't test it any further at the moment, without creating a data file. Post a copy of your input file so i can finish testing your code.
You are also using while() loops (incorrectly) in several locations that would be better served with else if statements.
Topic archived. No new replies allowed.