Seperis (seperis) wrote,
Seperis
seperis

  • Mood:

i have seen hell. it is arrays.

I have seen the face of hell. It is arrays combined with functions combined with infile combined with all the darkness of the soul.

Actually, it was hellish but since I did finish it, I guess it wasn't as bad as I thought.



#include iostream
#include string
#include iomanip
#include fstream

using namespace std;
using std::fixed;
using std::setprecision;

void readArray(string [], double []);
void highTemp(string[], double []);
void lowTemp(string[], double[]);
void calcAver(double[]);

int main()
{
//variables

string city[8] = "";
double temp[8] = {0.0};

//get temperatures
readArray(city, temp);

//get high temperature
highTemp(city, temp);

//get low temperature
lowTemp(city, temp);

//calculate average temperature
calcAver(temp);

cout << " " << endl;
cout << "You are done!" << endl;
cout << "And wasn't that a very special hell." << endl;
cout << "Please give me an A." << endl;
cout << " " << endl;

system("Pause");
return 0;
}

void readArray(string town[8], double temperature[8])
{
ifstream tempFile("temperatures.txt");
int x = 0;

tempFile >> town[x];
cout << "cityArray[" << x << "] = " << town[x] << endl;
tempFile >> temperature[x];
cout << "tempArray[" << x << "] = " << temperature[x] << endl;

for (int x = 1; x < 8; x = x + 1)
{
tempFile >> town[x];
cout << "cityArray[" << x << "] = " << town[x] << endl;
tempFile >> temperature[x];
cout << "tempArray[" << x << "] = " << temperature[x] << endl;
}
}

void highTemp(string place[8], double heat[8])
{
double highTemperature = 0.0;
string cityHigh = "";
int x = 0;

highTemperature = heat[0];

for (int x = 0; x < 8; x = x + 1)
{
if (highTemperature < heat[x])
{
highTemperature = heat[x];
cityHigh = place[x];
system("Pause");
}
}

cout << "High Temperature: " << highTemperature << endl;
cout << "High City: " << cityHigh << endl;
system("Pause");
}

void lowTemp(string place[8], double cold[8])
{
double lowTemperature = 0.0;
int x = 0;

lowTemperature = cold[0];

for (int x = 0; x < 8; x = x + 1)
{
if (lowTemperature > cold[x])
{
lowTemperature = cold[x];
system("Pause");
}
}

cout << "Low Temperature: " << lowTemperature << endl;
cout << "Low City: " << place[x] << endl;
system("Pause");
}

void calcAver(double averTemp[8])
{
double average = 0.0;
double total = 0.0;
int x = 0;

for (int x = 0; x < 8; x = x + 1)
{
total = total + averTemp[x];
}

average = total/8;

cout << "Average Temperature: " << average << endl;
system("Pause");
}

Known Problems

The readArray() function is completely wrong. I had to hard wire it in because I couldn't figure out how to initialize it otherwise. However, from what I understand, most of the class was having the same problem.

The lowTemp() function refuses to display the name of the low city under the variable string lowCity, so switched to place[x] in that function. However, highTemp() *will* allow the highCity variable to display correctly but refuses to do so for its place[x]. I--seriously can't figure that one out. They're clones of each other. Must try to fix.

readArray() is just--no idea. Gah.

However, it will run and give correct results, so at minimum partial credit. Must hope for a miracle. And hey, maybe study for my final sometime before tomorrow.

I need alcohol.



ETA: It's still funny; even when I'm close to snapping, this is still so incredibly, incredibly fun.
Tags: jenn's life, jenn's school
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 26 comments