DOUBLE DECIMAL STRUCTURE FUNCTION HELP

Hello, How do you display the numbers in the sample output at "4.00" and not as just "4"?

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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//Project last
//Jessica Brown 7 Decemeber 2011
// Demonstrates the use of an array of student structures
// Reading, sorting, searching, etc.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;

struct Studente
{
	char geNder;
	double score;
};


// Read all of the student objects from a text file into the array,
// one student at a time
int readStuArray( ifstream &inputFile, Studente everyone[], int maxSize )
{
	Studente temp;
	int count = 0;

	// Loop while the array is not full, and there is a first name to read
	// This assumes that if there is a first name, the rest of the data for
	// an employee will be there also.
	while ( count < maxSize && inputFile >> temp.geNder )
	{

		inputFile >> temp.score;

		everyone[count] = temp;

		count++;
	} // while

	return count;
} // readEmpArray()

// Display a single Student
void displayStu( const Studente &stu )
{
	cout << setw(1) << stu.geNder;
	cout << setw(5) << stu.score << endl;

} // displayStu()

// Display all of the studente objects in the array
void displayAll( const Studente everyone[], int size )
{
	cout << " Data " << endl;
	cout << "------" << endl;


		for ( int i = 0; i < size; i++ )
		displayStu( everyone[i] );


	cout << endl << endl;
} // displayAll()

//another function for calculations
void displayStats( const Studente everyone[], int size )
{
	int countm = 0;
	int countf = 0;
	double scorem = 0;
	double scoref = 0;


		for ( int i = 0; i < size; i++ )
		{
			if ( everyone[i].geNder == 'm' )
			{
			countm++;
			scorem += everyone[i].score;
			}//if
				else if ( everyone[i].geNder == 'f' )
				{
				countf++;
				scoref += everyone[i].score;
				}//else if
		}//for
	
	
	cout << "Sum of male scores: " << scorem << endl;
	cout << "Sum of female scores: " << scoref << endl;
	
	cout << endl << endl;
	
	cout << "Total male Count:" << countm << endl;
	cout << "Total female Count:" << countf << endl;
	
	cout << endl << endl;

	cout << "Average male scores: " << (scorem /countm)  << endl;
	cout << "Average female scores: " << (scoref / countf) << endl;
	
	cout << endl << endl;

} //displayStats

int main()
{
	const int MAX_STU = 100;
	ifstream inputFile( "Project3-input.txt" );
	Studente everyone[MAX_STU];
	int count;
	

	if ( !inputFile )
	{
		cout << "Unable to open input file!" << endl;
		system( "pause" );
		exit( 1 );
	}

	// Read the Student objects from the file
	count = readStuArray( inputFile, everyone, MAX_STU );

	displayStats( everyone, count );

	displayAll (everyone, count );

	system( "pause" );
	return( 0 );
} // main()


This is the data file that is the input.

f 3.40
f 4.00
m 3.56
m 3.80
f 2.30
f 3.95


This is a sample of what it is supposed to look like.

Sum of male   scores: 46.67
Sum of female scores: 46.99

Total male   count: 14
Total female count: 14

Average male   score: 3.33
Average female score: 3.36


Data
-------
f  3.40
f  4.00
m  3.56
m  3.80
f  2.30
f  3.95
m  3.90
m  4.00
m  2.00
f  4.00
f  2.80
m  3.70
m  2.98
f  3.89
m  4.00
f  3.90
m  1.90
m  2.90
f  1.50
f  2.67
m  3.80
m  2.35
f  2.90
f  3.70
f  4.00
m  3.78
m  4.00
f  3.98
Last edited on
Topic archived. No new replies allowed.