Code
#include <iostream>
#include <fstream>
using namespace std;
void introduction();
int validtemperatures(int, int, int);
double findavg(int , int , int)
void whatseason(double)
int main()
{
int temp1, temp2, temp3, valid, validtemp=0, invalidtemp=0, total;
ifstream infile("text.txt");
ofstream outfile("text.txt");
introduction();
infile >> temp1 >> temp2 >> temp3;
while(infile)
{
cout << "Temperatures inputted are: "<< temp1 << ", " << temp2 << ", and " << temp3 << endl;
validtemperatures(temp1, temp2, temp3, valid);
if(valid == 1){
cout << "The set of temperatures is valid" << endl;
classify(temp1, temp2, temp3);
validtemp++;
}
else{
cout << "The set of temperatures is not valid" << endl;
invalidtemp++;
}
total++;
}
infile.close();
return 0;
}
//This function explains the assingment
void introduction()
{
outfile << "" << endl;
outfile << "Assignment4 " << endl;
outfile << "Valid temperatures are within the range -10 and 110 " << endl;
outfile << "The groups of temperature can only be valid if the groups are within their seasons " << endl;
return;
}
//This function finds if the temperatures are valid
int validtemperatures(int temp1, int temp2, int temp3)
{
int count = 0;
if(temp1 > 110 || temp1 < -10)
cout << temp1 << "is an invalid temperature" << endl;
else
count++;
if(temp2 > 110 || temp2 < -10)
cout << temp2 << "is an invalid temperature" << endl;
else
count++;
if(temp3 > 110 || temp3 < -10)
cout << temp3 << "is an invalid temperature" << endl;
else
count++;
if(temp1 < 110 && temp1 > -10 && temp2 < 110 && temp2 > -10 && temp3 < 110 && temp3 > -10)
return 1;
else
return 0;
}
//This function finds the average of the three valid temperatures
double findavg(int temp1, int temp2, int temp3)
{
double avg;
avg = (temp1 + temp2 + temp3)/3.0
return avg;
}
//This function finds the season through the three temperatures given
void whatseason(double avgtemp)
{
if(avgtemp >= 100)
cout << "The average temperature is " << avgtemp << ", it is roasting season" << endl;
if(avgtemp >= 80 || avgtemp < 100)
cout << "The average temperature is " << avgtemp << ", it is summer" << endl;
if(avgtemp >= 60 || avgtemp < 80)
cout << "The average temperature is " << avgtemp << ", it is spring" << endl;
if(avgtemp >= 40 || avgtemp < 60)
cout << "The average temperature is " << avgtemp << ", it is fall" << endl;
if(avgtemp >= 0 || avgtemp < 40)
cout << "The average temperature is " << avgtemp << ", it is winter" << endl;
if(avgtemp < 0)
cout << "The average temperature is " << avgtemp << ", it is freezin'' season" << endl;
}
Okay, finished the next two functions.
Now the instruction for what I NEED to do with the classify is this.
Quote
If all the temperatures are valid, main will call a function classify and send it the three integers representing valid temperatures. The function classify will call the rest of the functions: It will call the function findavg, which will find the average of the three temperatures and return the average to classify. Then classify will send the average to the function whatseason to determine what season this average represents. Then classify will return to the main program
Updated