Why did the code keep saying expected-primary expression? #include #include #include using namespace std; void readFile ( float, float); void average(float, float); void highest_lowest(float, float, int); void writeReport(float, float, float, float, int); struct WeatherData { float rain; float hiT, lowT, avgT; //rain in a month, high temperature, low temperature, average temperature respectively int rain_days; string month; }; void readFile (WeatherData mth[], float tot_rain, float avgR) { //name_mth=month ifstream fin; int i, n_mth; for(i=0; i> WeatherData mth[i].rain; fin >> WeatherData mth[i].rain_days; fin >> WeatherData mth[i].hiT; fin >> WeatherData mth[i].lowT; fin >> WeatherData mth[i].month; WeatherData mth[i].avgT = (WeatherData mth[i].hiT + WeatherData mth[i].lowT) / 2; tot_rain = tot_rain + WeatherData mth[i].rain; } avgR = tot_rain/12; highest_lowest(WeatherData mth, tot_rain, avgR) } void highest_lowest(WeatherData mth[], float tot_rain, float avgR) { float high=0.00, low=35; int j, n_mth, hi_mth, low_mth; string nhi_mth, nlow_mth; for(j=0; j low_mth) { low_mth = WeatherData mth[j].lowT; nlow_mth = WeatherData mth[j].month; low_mth = j + 1; } } } void writeReport(WeatherData mth[], float rain, float hiT, float lowT, float avgT, int rain_days) { ofstream fout; fout.open("Output.txt"); float tot_rain, avgR, high, low, hi_mth, nhi_mth, low_mth, nlow_mth; int i, n_mth; fout << "Total Rainfall: " << fixed << setprecision(2) << tot_rain << endl; fout << "Average Monthly Rain: " << fixed << setprecision(2) << avgR << endl; fout << "Highest temperature: " << high << "(Month " << hi_mth << ": " << nhi_mth << ")" << endl; fout << "Lowest temperature: " << low << "(Month " << low_mth << ": " << nlow_mth << ")" << endl; fout << "Month" << "\t\tRain" << "\tRain days" << "\tHi TEMP" << "\tLo TEMP" << "\tAvg TEMP" << endl; fout << "=========" << "\t======" << "\t=========" << "\t=======" << "\t=======" << "\t========" << endl; for(i=0; i

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Why did the code keep saying expected-primary expression?

#include <iostream>
#include <iomanip>
#include <fstream>

using namespace std;

void readFile ( float, float);
void average(float, float);
void highest_lowest(float, float, int);
void writeReport(float, float, float, float, int);

struct WeatherData {

float rain;
float hiT, lowT, avgT; //rain in a month, high temperature, low temperature, average temperature respectively
int rain_days;
string month;
};

void readFile (WeatherData mth[], float tot_rain, float avgR) { //name_mth=month

ifstream fin;

int i, n_mth;

for(i=0; i<n_mth; i++) {

fin >> WeatherData mth[i].rain;
fin >> WeatherData mth[i].rain_days;
fin >> WeatherData mth[i].hiT;
fin >> WeatherData mth[i].lowT;
fin >> WeatherData mth[i].month;

WeatherData mth[i].avgT = (WeatherData mth[i].hiT + WeatherData mth[i].lowT) / 2;
tot_rain = tot_rain + WeatherData mth[i].rain;
}
avgR = tot_rain/12;

highest_lowest(WeatherData mth, tot_rain, avgR)
}

void highest_lowest(WeatherData mth[], float tot_rain, float avgR) {

float high=0.00, low=35;
int j, n_mth, hi_mth, low_mth;
string nhi_mth, nlow_mth;

for(j=0; j<n_mth; j++) {

if(WeatherData mth[j].hiT < hi_mth) {

hi_mth = WeatherData mth[j].hiT;
nhi_mth = WeatherData mth[j].month;

hi_mth = j + 1;
}
if (WeatherData mth[j].lowT > low_mth) {

low_mth = WeatherData mth[j].lowT;
nlow_mth = WeatherData mth[j].month;

low_mth = j + 1;
}
}
}

void writeReport(WeatherData mth[], float rain, float hiT, float lowT, float avgT, int rain_days) {

ofstream fout;
fout.open("Output.txt");

float tot_rain, avgR, high, low, hi_mth, nhi_mth, low_mth, nlow_mth;
int i, n_mth;

fout << "Total Rainfall: " << fixed << setprecision(2) << tot_rain << endl;
fout << "Average Monthly Rain: " << fixed << setprecision(2) << avgR << endl;
fout << "Highest temperature: " << high << "(Month " << hi_mth << ": " << nhi_mth << ")" << endl;
fout << "Lowest temperature: " << low << "(Month " << low_mth << ": " << nlow_mth << ")" << endl;

fout << "Month" << "\t\tRain" << "\tRain days" << "\tHi TEMP" << "\tLo TEMP" << "\tAvg TEMP" << endl;
fout << "=========" << "\t======" << "\t=========" << "\t=======" << "\t=======" << "\t========" << endl;

for(i=0; i<n_mth; i++) {

fout << WeatherData mth[i].month << "\t\t";
fout << WeatherData mth[i].rain << "\t";
fout << WeatherData mth[i].rain_days << "\t";
fout << WeatherData mth[i].hiT << "\t";
fout << WeatherData mth[i].lowT << "\t";
fout << WeatherData mth[i].avgT;
}
fout.close();
}

int main() {

float tot_rain, avgR;
int n_mth=12;
WeatherData mth[n_mth];

ifstream fin;
fin.open("data2.txt");

if(!fin.eof()) {

cout << "ERROR: File cannot be opened! ";
exit(1);
}
else if(){

readFile (WeatherData mth, tot_rain, avgR);
fin.close();
}
}

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Name constants and Literal values
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education