The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 305 Weeks Ago, 1 Day Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
I need help with:
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 the lowest temperatures for the year (and the months they occurred in), and the average of all the monthly average temperatures.
Input Validation: Only accept the temperature within the range between -100 and +140 degrees Fahrenheit.
Â
I have some written, but I keep getting this at the very end of the input while debugging in Visual Studio:
"Exception thrown: read access violation.
std::_String_alloc<std::_String_base_types<char,std::allocator<char> > >::_Mysize(...) returned 0x66DA5BE8."
Please help!
Â
Here is what I have so far:
#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++)
  {
     //total rainfall
     cout << "Enter the total rainfall for the month of " << month[i] << ": ";
     cin >> months[i].totalRainfall;
     //rainfall validation
     while (months[i].totalRainfall < 0)
     {
        cout << "Rainfall cannot be less than zero (0).n";
        cout << "tEnter the total rainfall: ";
        cin >> months[i].totalRainfall;
     }
     //temp high
     cout << "Enter the temperature high: ";
     cin >> months[i].highTemp;
     //temp high validation
     while (months[i].highTemp < -100 || months[i].highTemp > 140)
     {
        cout << "Error: Temperature must be in the range of -100F through 140F.n";
        cout << "tHigh Temperature: ";
        cin >> months[i].highTemp;
     }
    Â
     //temp low
     cout << "Enter the temperature low: ";
     cin >> months[i].lowTemp;
     //temp low validation
     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;
     }
  }
  //monthly average temp 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;
     }
    Â
     if (months[i].lowTemp < lowest)
     {
        lowest = months[i].lowTemp;
        lowmonth = i;
     }
  }
  avgsum = 0;
  //average of average
  for (int i = 0; i < 12; i++)
  {
     avgsum = avgsum + months[i].avgTemp;
  }
  //displaying 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");
}
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly