Displaying Hjighest and Lowest number in C++ -
i trying way. seems more simplified. trying figure out how include month names , program output name of rainiest month not number user inputs.
#include <iostream> #include <conio.h> using namespace std; int main () { int a[12]; int x; (x=0; x<12; x++) { cout << "insert days of rainfall month "<<x+1<<endl; cin >>a[x]; } int max; int min; max = a[0]; min = a[0]; int e=0; while (e<12) { if (a[e]>max) { max = a[e]; } else if (a[e]<min) { min = a[e]; } e++; cout<<"the rainiest month " <<max<<endl; cout<<"the least rainy month " <<min<<endl; getch (); return 0; } system("pause"); return exit_success; }
your average
calculation off little, have take consideration order of operations when comes math. multiplication , division done first, addition , subtraction. end dec
divided 12, , add other days it. fix this, need wrap additions of of months in parentheses force addition happen first, divide after. in case, can use year
variable since of months added , divide 12.
as far question goes, want show highest , lowest values input, don't see attempt solve in code. feel less inclined write code give brief explanation of need instead. @ value each month, each time @ next month, compare current highest , current lowest values remember. when new month has new higher, or new lower, value replace value remember. once cycle through every month end highest , lowest values.
Comments
Post a Comment