1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
#include<iostream>
#include<iomanip>
javascript:PostPreview()
using namespace std;
void Display(string month_name,int rainfall);
int main() {
double average, total_rain, highest_rain, lowest_rain, data, nmax = 0, nmin = 9999, rainfall [16];
string month, city, name;
const char* month_name[16];
int hm;
int mm;
int max_counter = 0;
int min_counter = 0;
cout << "What is your name?" << endl;
getline(cin, name);
cout << "What is your city?" << endl;
getline(cin, city);
month_name[1] = "January";
month_name[2] = "February";
month_name[3] = "March";
month_name[4] = "April";
month_name[5] = "May ";
month_name[6] = "June";
month_name[7] = "July";
month_name[8] = "August";
month_name[9] = "September";
month_name[10] = "October";
month_name[11] = "November";
month_name[12] = "December";
for (int month = 1; month < 13; month++)
{
cout << "Enter amount of rainfall for " << month_name[month] << ": ";
cin >> data;
cout << endl;
total_rain += data;
rainfall[month] = data;
}
for(int loop2 = 1;loop2 < 13;loop2++)
{
if(rainfall[loop2] == nmin)
{
nmin = rainfall[loop2];
min_counter++;
mm = loop2;
}
if(rainfall[loop2] < nmin)
{
nmin = rainfall[loop2];
mm = loop2;
}
}
for(int loop = 1;loop < 13;loop++)
{
if(rainfall[loop] == nmax)
{
nmax = rainfall[loop];
max_counter++;
hm = loop;
}
if(rainfall[loop] > nmax)
{
nmax = rainfall[loop];
hm = loop;
}
}
highest_rain = nmax;
lowest_rain = nmin;
average = total_rain / 12;
cout <<"The rainfall report for " << city << " prepared by " << name << ":"<<endl;
cout << endl;
for(int i = 1;i < 13;i++)
{
Display (month_name[i],rainfall[i]);
}
cout << " -------------1--2--3--4--5--6--7--8--9--10-11-12-13-14-15-16-17-18-19-20"<< endl;
cout <<setw(20)<<left<< "Average Rainfall" << " " <<fixed<<setprecision(2)<< average << " Inches" << endl;
cout << endl;
cout <<setw(30)<<left<< "Month with Lowest Rainfall" <<" "<<setw(10)<<left<<month_name[mm]<<" "<< fixed<<setprecision(2)<<nmin<< endl;
cout<<setw(30)<<left<< "Month with Highest Rainfall" <<" "<<setw(10)<<left<<month_name[hm]<<" "<< fixed<<setprecision(2)<< nmax<< endl;
}
void Display(string month_name,int rainfall)
{
cout << month_name;
if(month_name != "February" && month_name != "September" && month_name != "November" && month_name != "December")
{
cout << "\t";
}
cout << "\t| ";
for(int i = 0;i < rainfall;i++)
{
cout << "* ";
}
cout << endl;
}
|