Need help figuring out how to write certain program!

In a class that I am in, we are supposed to write a program that can
1) List the schools and the tuition of the schools in Cincinnati with tuition below 20000. Also list the number of schools that meet these criteria.
2) Calculate and display the average tuition of schools with more than 10000 enrolled students. Indicate the tuition of BGSU and also
indicate if BGSU tuition is higher or lower than average.
3) Give the name and tuition of the three most expensive schools. You can assume that the top three schools have different tuitions than all others (there are no "ties")

The program is to take data from a .dat file and read it so as to get the information for the different parts. Additionally, the program is to use several functions to perform the tasks, as we have recently learned the basics of functions in class.
I have a portion of the program written, but it generally does not appear to be working out as I write it.

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
  #include <iostream>
#include <fstream>
#include <string>

using namespace std;

ifstream file; /*declaring ifstream?? I wasn't quite sure where to put this, 
			   given my function declarations*/

void dashline(int numChar) //function to include a dashed line
{
	int i = numChar;
	while (i > 1)
	{
		cout << "-";
		i--;
	}
	while (i == 1)
	{
		cout << "-\n";
		i--;
	}
}

void findCity_and_Tuition() //function to perform part #1
{
	string city, college, stopper;
	int tuition, i;
	file.open("OH-in.dat"); //open file
	
	i = 1;
	while (i > 0)
	{
		file >> stopper;
		while (stopper != "***") //the .dat file has "***" at the end of the usable data
		{
			file >> city; /*my attempting to draw out certain points of data from the .dat--I have
						  no idea what I am doing in this section...*/
			if (city == "Cincinnati")
			{
				file >> tuition;
				if (tuition >= 20000)
				{
					cout << city << tuition;
				}
			}
		}
		i = 0;
	}

}
/*Note: the .dat file includes data such that it lists the school, then the city of the school,
then the current enrollment of the school, and then the current tuition for the school.*/

int main()
{
	string cout1, cout2, cout3; //this is my having the dashed line be the same length as the text
	cout1 = "Schools located in Cincinnati with tuition below $20,000";
	cout2 = "Average tuition and how it compares to BGSU";
	cout3 = "Top three most expensive schools in Ohio";

	cout << cout1 << endl;
	dashline(cout1.length());
	findCity_and_Tuition(); //attempting to call the function

	cout << cout2 << endl;
	dashline(cout2.length());

	cout << cout3 << endl;
	dashline(cout3.length());



	system("pause");
	return 0;
}
Last edited on
Topic archived. No new replies allowed.