Help with my project

closed account (9yqpDjzh)
I just started learning c++ and I have to write a program which reads data from an input file, then the output has to be shown on the screen and also stored in an output file. This is what the input file looks like
Raymond F. Bixbyouster
443 Delmont Avenue
Strykersville NY 14141
122678.00 125 15
Ellie May Clampet
52 Maplecrest Road
Scio, NY 14333
35410.00 75 10
Hickory T. Brewster
117 Slater lane
Hermitage, NY 143441
12974.00 25 00


I did everything but it doesn't seem to be working properly here's my code
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
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <string>
#include <math.h>

using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) 
{
	ifstream inFile;
	ofstream outFile;
	
	string employeeName;
	string street;
	string citystatezip;
	double yearlySalary;
	int ratingPercent;
	int weightFactor;
	double subtotal;
	double bonusAmount;
	
	inFile.open("Proj3Input.dat");
	
	if(!inFile)
	{
		cout<<"Error opening Project3Input.dat"<<endl;
		return 1;
	}
	
	outFile.open("Proj3Output.dat");
	
	if (!outFile)
	{
		cout<<"Error opening Proj3Output.dat"<<endl;
		return 1;
	}
	
	outFile<<fixed<<showpoint;
	outFile<<setprecision(2);
	
	getline(inFile, employeeName);
	getline(inFile, street);
	getline(inFile, citystatezip);
	inFile>>yearlySalary>>ratingPercent>>weightFactor;
	
	subtotal = yearlySalary*ratingPercent/100;
	bonusAmount = subtotal*weightFactor/100;
	bonusAmount = floor(bonusAmount*100+0.5)/100;
	
	cout << left << "Employee Name: " << right << employeeName << endl;
	cout << left << "Mailing Address: " << right << street << endl;
	cout << right << citystatezip << endl;
	cout << endl;
	
	outFile << left << "Yearly Gross Salary: $" << right << yearlySalary << endl;
	outFile << left << "Rating Percent: " << right << ratingPercent << "%" << endl;
	outFile << left << "Subtotal: $" << right << subtotal << endl;
	outFile << left << "Level Weight Factor: " << right << weightFactor << "%" << endl;
	outFile << left << "Gross Bonus Amount: $" << right << bonusAmount << endl;
	
	inFile.close();
	outFile.close();
	
	system("PAUSE");
	return EXIT_SUCCESS;
	
}
What do you mean by "it doesn't seem to be working properly"? Does it install a virus? Does it add you to an FBI watch list? Does it prevent you from getting a tax refund? Does make your GPU explode? You need to be specific.
closed account (9yqpDjzh)
It doesn't display the desired results..when i try to run the program it only displays the name and address of the first person and nothing else..and when i go to look at the output file it doesn't contain any addresses, it only contains the gross salary, rating percent, subtotal, level weight factor and gross bonus amount of the first person... So i guess my question is how do i get the program to display the name, address, gross salary, rating percent, subtotal, level weight factor and gross bonus of ALL 3 people AND also store that information into the output file.
I don't see any loops anywhere in your program, why would you expect any part of your code to run more than once?
closed account (9yqpDjzh)
Well how do i make it run more than once? I figured out everything else so that's the only thing that i need to fix
Last edited on
closed account (9yqpDjzh)
I can't figure out how to use that in my program...
You can't think of anything to do with lines 45 to 63 that involve a for loop?
closed account (9yqpDjzh)
Well I'm not sure I've never used loops before so I'm not really sure how for works but i guess i could make it so that if there's a character then it keeps going and if there's no character it stops, but I don't know how to do that the one in the example is with numbers
Will the file have a different number of things in it, or will it always be the same?
closed account (9yqpDjzh)
Well in my project it's always gonna be the same but we have to make it so that it runs until all data is read.. So I guess the other way would be to maybe run until it reaches an empty line? If that's an option..but then the last line might not be an empty line and then it's gonna keep running forever and I don't want that. I don't know I can't figure it out
Can you give two sample input files with a different number of things so we can see what we're up against here?
Topic archived. No new replies allowed.