Question

The following is a program from Starting out with C++ by Toni Gaddis. I am getting the following error messages pertain...

The following is a program from Starting out with C++ by Toni Gaddis. I am getting the following error messages pertaining to the lines: cin>>month[i].lowTemp; and months[i].avgTemp = (months[i].highTemp + month[i].lowTemp)/2;

The error messages read as follows: error C2039: 'lowTemp': is not a member of 'std::basic_string<_Elem,_Traits,_Ax>' and it continues. The second error message is identical.

The program is as follows:

Ch. 11, Assignment #3. pg. 646. Program #4.

//Weather Statistics.

//Write a program that uses a structure to store the following weather data

//for a particular month:

//Total Rainfall

//High Temperature

//Low Temperature

//Average Temperature

//The program should have an array of 12 structures to hold weather data for

//an entire year. When the program runs, it should ask the user to enter data

//for each month. (The average temperature should be calculated.) Once the

//data are entered for all the months, the program should calculate and

//display the average monthly rainfall, the total rainfall for the year,

//the highest and lowest temperatures for the year (and the months they

//occur in), and the average of all the monthly average temperatures.

//Input Validation: Only accept temperatures within the range between

//-100 and +140 degrees Fahrenheit.

//Header file section

//#include "stdafx.h"

#include<iostream>

#include<string>

using namespace std;

struct weather

{

double totalRainfall;

double highTemp;

double lowTemp;

double avgTemp;

};

void main()

{

weather months[12];

double total =0, highest, lowest, avgsum;

int highmonth, lowmonth;

string month[12]= {"January", "February", "March", "April", "May", "June",

"July", "August", "September", "October", "November",

"December"};

for(int i=0; i<12; i++)

{

cout<<"Enter total rainfall for month "<<month[i]<<": ";

cin>>months[i].totalRainfall;

cout<<"Enter high temperature: ";

cin>>months[i].highTemp;

while (months[i].highTemp < -100 || months[i].highTemp > 140)

{

cout<<"ERROR: Temperature must be in the range of "

   <<"-100 through 140.\n";

cout<<"\tHigh Temperature: ";

cin>>months[i].highTemp;

}

cout<<"Enter low temperature: ";

cin>>months[i].lowTemp;

while (months[i].lowTemp < -100 || months[i].lowTemp > 140)

{

cout<<"ERROR: Temperature must be in the range of "

   <<"-100 through 40.\n";

cout<<"\tLow Temperature: ";

cin>>month[i].lowTemp;

}

}

//Calculate the monthly average temperature and total rainfall.

for (int i=0; i<12; i++)

{

total=total + months[i].totalRainfall;

months[i].avgTemp= (months[i].highTemp + month[i].lowTemp)/2;

}

highest=months[0].highTemp;

lowest=months[0].lowTemp;

for(int i=1; i<12; i++)

{

if(months[i].highTemp>highest)

{

highest=months[i].highTemp;

highmonth=i;

}

if(months[i].lowTemp<lowest)

{

lowest=months[i].lowTemp;

lowmonth=i;

}

}

avgsum = 0;

//Calculate the average.

for(int i=0; i<12; i++)

{

avgsum=avgsum+months[i].avgTemp;

}

//Display the calculated data.

cout<<"Average monthly rainfall: "<<total/12<<endl;

cout<<"Total monthly rainfall: "<<total<<endl;

cout<<"Highest rainfall in "<<month[highmonth]<<"is: "<<highest<<endl;

cout<<"Lowest rainfall in "<<month[lowmonth]<<"is: "<<lowest<<endl;

cout<<"Average of average temperatures is: "<<avgsum/12<<endl;

system("pause");

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Please check this Solution please

//error caused because here yo used month intstead of months :):)

#include

#include

using namespace std;

struct weather

{

double totalRainfall;

double highTemp;

double lowTemp;

double avgTemp;

};

int main()

{

weather months[12];

double total =0, highest, lowest, avgsum;

int highmonth, lowmonth;

string month[12]= {"January", "February", "March", "April", "May", "June",

"July", "August", "September", "October", "November",

"December"};

for(int i=0; i<12; i++)

{

cout<<"Enter total rainfall for month "<

cin>>months[i].totalRainfall;

cout<<"Enter high temperature: ";

cin>>months[i].highTemp;

while (months[i].highTemp < -100 || months[i].highTemp > 140)

{

cout<<"ERROR: Temperature must be in the range of "

<<"-100 through 140.\n";

cout<<"\tHigh Temperature: ";

cin>>months[i].highTemp;

}

cout<<"Enter low temperature: ";

cin>>months[i].lowTemp;

while (months[i].lowTemp < -100 || months[i].lowTemp > 140)

{

cout<<"ERROR: Temperature must be in the range of "

<<"-100 through 40.\n";

cout<<"\tLow Temperature: ";

cin>>months[i].lowTemp;

}

}

//Calculate the monthly average temperature and total rainfall.

for (int i=0; i<12; i++)

{

total=total + months[i].totalRainfall;

months[i].avgTemp= (months[i].highTemp + months[i].lowTemp)/2;

}

highest=months[0].highTemp;

lowest=months[0].lowTemp;

for(int i=1; i<12; i++)

{

if(months[i].highTemp>highest)

{

highest=months[i].highTemp;

highmonth=i;
cout<

}

if(months[i].lowTemp

{

lowest=months[i].lowTemp;

lowmonth=i;
cout<

}

}

avgsum = 0;

//Calculate the average.

for(int i=0; i<12; i++)

{

avgsum=avgsum+months[i].avgTemp;

}

//Display the calculated data.

cout<<"Average monthly rainfall: "<

cout<<"Total monthly rainfall: "<

cout<<"Highest rainfall in "<

cout<<"Lowest rainfall in "<

cout<<"Average of average temperatures is: "<

return 0;

}

Add a comment
Answer #2

on lines 77 and 91, you have mistyped month[i].lowTemp instead of months[i].lowTemp.

Please correct it to months[i].lowTemp.

and when we compile it, result/output would be :

Add a comment
Know the answer?
Add Answer to:
The following is a program from Starting out with C++ by Toni Gaddis. I am getting the following error messages pertain...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ********** PLEASE PROVIDE IN JAVA & NEW SET OF ALGORITHM For this lab use the program...

    ********** PLEASE PROVIDE IN JAVA & NEW SET OF ALGORITHM For this lab use the program at the bottom to sort an array using selection sort. Write a selection sort to report out the sorted low values: lowest to highest. Write another to report out the sorted high values – highest to lowest. Last but not least, the program should output all the values in the array AND then output the 2 requested sorted outputs. -----> MY OLD PROGRAM BELOW...

  • Need help with a C++ program. I have been getting the error "this function or variable...

    Need help with a C++ program. I have been getting the error "this function or variable may be unsafe" as well as one that says I must "return a value" any help we be greatly appreciated. I have been working on this project for about 2 hours. #include <iostream> #include <string> using namespace std; int average(int a[]) {    // average function , declaring variable    int i;    char str[40];    float avg = 0;    // iterating in...

  • C++ getline errors I am getting getline is undefined error messages. I would like the variables...

    C++ getline errors I am getting getline is undefined error messages. I would like the variables to remain as strings. Below is my code. #include <iostream> #include<string.h> using namespace std; int index = 0; // variable to hold how many customers are entered struct Address //Structure for the address. { int street; int city; int state; int zipcode; }; // Customer structure struct Customer { string firstNm, lastNm; Address busAddr, homeAddr; }; // Functions int displayMenu(); Customer getCustomer(); void showCustomer(Customer);...

  • Am I getting this error because i declared 'n' as an int, and then asking it...

    Am I getting this error because i declared 'n' as an int, and then asking it to make it a double? This is the coude: #include "stdafx.h" #include <iostream> #include <fstream> #include <string> #include <algorithm> #include <vector> using namespace std; void sort(double grades[], int size); char calGrade(double); int main() {    int n;    double avg, sum = 0;;    string in_file, out_file;    cout << "Please enter the name of the input file: ";    cin >> in_file;   ...

  • [C++] Using Files—Total and Average Rainfall Write a program that reads in from a file a...

    [C++] Using Files—Total and Average Rainfall Write a program that reads in from a file a starting month name, an ending month name, and then the monthly rainfall for each month during that period. As it does this, it should sum the rainfall amounts and then report the total rainfall and average rainfall for the period. For example, the output might look like this: During the months of March–June the total rainfall was 7.32 inches and the average monthly rainfall...

  • Write a program that uses a two-dimensional array to store the highest and lowest temperatures for...

    Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. You should also have a parallel array to store the names of the 12 months. The program should read the Month's names, and the temperatures from a given input file called temperature.txt. The program should output the highest and lowest temperatures for the year, and the months that correspond to those temperatures. The program must use the following functions:...

  • IN C++ FORMAT it will have a txt file with January 0 -10 -20 -12 February...

    IN C++ FORMAT it will have a txt file with January 0 -10 -20 -12 February 0 20 -30 -10 March 5 45 20 32 April 25 65 45 55 May 12 75 32 66 June 18 85 65 72 July 6 98 88 90 August 18 102 82 91 September 16 85 65 73 October 12 72 45 59 November 5 62 30 45 December 0 46 -15 33 Write a program using structures to store the following weather...

  • C Part 1 Given a structure that store the highest temperature (HighTemp) and the lowest temperature (LowTemp) of a day:...

    C Part 1 Given a structure that store the highest temperature (HighTemp) and the lowest temperature (LowTemp) of a day: typedef struct {       char DayOfMonth[31];     /*  e.g.  “May 13”,  “July 9”  */       int HighTemp;         /*  the highest temperature of that day  */       int LowTemp;         /* the lowest temperature of that day */ } DayTemp; DayTemp  Temperature[365]; Temperature is an array of structure DayTemp.  Write a function that will return the average of HighTemp for a given number of days (NumberDay)...

  • I need this asap. C++ please A A Ap Aa Consolas 14 AaBbCcDd AaBbCcDd AaBbCc Editing...

    I need this asap. C++ please A A Ap Aa Consolas 14 AaBbCcDd AaBbCcDd AaBbCc Editing ste 1 No Spac.. Heading 1 В I 1 Normal x A U A v ab х. Dictate ipboard Font Paragraph Styles Voice Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and the highest and lowest temperatures for the year. Your program...

  • The following program is in c++ ; I am trying to read in games from a...

    The following program is in c++ ; I am trying to read in games from a file and when doing so I am only reading in parts of the file. It is giving me a segmentation fault error I am going to post my code below if anyone is able to help me debug the program I would greatly appreciate it. The program is too large to be submitted as a single question on here :( --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- void Business::addGamesFromFile() {...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT