4 Seasons C++ HELP | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

4 Seasons C++ HELP

Hello this question has had me stuck for a few hours now and i am becoming very frusturated can anyone tell me how to fix and solve this problem? Write a program that determines the average rainfall for the four season; winter is December, January, and February; spring is March, April, and May; summer is June, July, and August; fall is September, October, and November. Your program should ask the user to input the rainfall for each month, then calculate the average rainfall for each season, and finally report the average rainfall for the winter, spring, summer, and fall. #include <iostream> using namespace std; int main() { //declared variables float December = 0.0; float January = 0.0; float February = 0.0; int WINTER = 0.0; float March = 0.0; double April = 0.0; double May = 0.0; double SPRING = 0.0; double June = 0.0; double July = 0.0; double August = 0.0; double SUMMMER = 0.0; double September = 0.0; double October = 0.0; double November = 0.0; double FALL = 0.0; //input section cout << "please enter Decembers rainfall"; cin >> December;cout << endl; cout << "please enter Januarys rainfall"; cin >> January;cout << endl; cout << "please enter Februarys rainfall"; cin >> February;cout << endl; WINTER = December + January + February / 3; return 0; }

11th Jan 2022, 4:45 PM
Gabriel Reyes
2 Answers
+ 6
Gabriel Reyes , ▪︎ the code uses double, float and int for the input values. use double for all ▪︎ for the calculation of the average value you need to set the addition of the months inside a pair of parenthesis, the division has to be done outside the parenthesis. ▪︎you get a number of "warnings" from the compiler, because you have defined variables that are not yet used. complete the code, so that the messages disappear.
11th Jan 2022, 5:08 PM
Lothar
Lothar - avatar
+ 4
You use int type for <WINTER> there, calculating average of 3 floating point value into int value. The rainfall data for other seasons uses double, why float is used for winter months?
11th Jan 2022, 5:12 PM
Ipang