want to find the fault

May 24, 2013 at 10:42am
i write a programme to following question but it does not run correctly .what is wrong with it?

question :

A file is required to maintain the salary of employees at ABC Company. The program
should allow the user to enter at least three (3) records of new employee data to the file.
The file should accept Employee number, Employee name and the Basic salary and
calculate the Net Salary and display it.
The formula required to calculate the Net Salary is Net Salary = Basic Salary + 2500
Write a complete C++ program for the above given tasks.



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
#include <iostream>
#include <conio.h>
#include <fstream>
#include <sstream>

using namespace std;

void main ()
{

	string employee_name[3],basic_salary[3],employee_number[3];;
	int employee_number_int[3];
	float basic_salary_float[3];

	cout <<"\n\t\tABC company"<<endl;

	for(int k=0;k<3;k++)
	{
	cout <<"\tEnter the name of the employee"<<endl;
	getline(cin,employee_name[k]);

	cout <<"\tEnter the number of the employee"<<endl;
	getline(cin,employee_number[k]);
	stringstream(employee_number[k])>>employee_number_int[k];

	cout <<"\tEnter the basic salary of the employee"<<endl;
	getline(cin,basic_salary[k]);
	stringstream(basic_salary[k])>>basic_salary_float[k];

	cin.clear();
	}
	
	ofstream aFile("Net salary.txt",ios::app);
	aFile<<"\n\t\tABC company"<<"\n\t\t___________";
	aFile<<"\n\t"<<"employee_name"<<"\t"<<"employee_number_int"<<"\t"<<"basic_salary_float"<<"\t"<<"Net salary"<<endl;

	for(int i=0;i<3;i++)
	{
		aFile<<"\n\t"<<employee_name[i]<<"\t"<<employee_number_int[i]<<"\t"<<basic_salary_float[i]<<"\t"<<2500+basic_salary_float[i];
	}
	aFile.close();


	_getch();
}
Last edited on May 24, 2013 at 11:15am
May 24, 2013 at 10:49am
What problem exactly?
Also you are missing closing bracket at the end of main(). And your for loop.
May 24, 2013 at 11:02am
The programm did not do the calculation part after entering data.
May 24, 2013 at 11:27am
Works for me. Remember, you are outputting into file, not on screen.
And it is int main(), not void main(). You should probably change compiler if it allows you to do that.
Topic archived. No new replies allowed.