Ask coding questions

← Back to all posts
##### Whle Lopp

My prof wants me to finish writing this code so it will output and also write a while loop for it but has not been teaching us much just telling us to read and what not and teach ourselves so i am having trouble on even knowing what to do

``````#include <iostream>
#include <fstream>
using namespace std;

int main()
{
// Fill in the code to define and initialize to 1 the variable month

float total = 0, rain;

cout << "Enter the total rainfall for month " << month << endl;
cout << "Enter -1 when you are finished" << endl;

// Fill in the code to read in the value for rain

// Fill in the code to start a while loop that iterates
// while rain does not equal -1
{
// Fill in the code to update total by adding it to rain

// Fill in the code to increment month by one

cout << "Enter the total rainfall in inches for month "
<< month << endl;
cout << "Enter -1 when you are finished" << endl;

// Fill in the code to read in the value for rain
}

if (month == 1)
cout << "No data has been entered" << endl;

if (month == 1)
cout << "No data has been entered" << endl;

else
cout << "The total rainfall for the " << month - 1
<< " months is " << total << " inches." << endl;

return 0;
}``````
##### Comments
hotnewtop
Bookie0 (5983)

Check this out for `while` loops in C++.

Here's an example:

``````#include <iostream>
using namespace std;

int counter = 0; // declaring a variable

while (counter < 11) // will run 10 times (until counter is not bigger than 11)
{
cout << counter <<  endl; // outputs the variable counter
counter ++; // increments the variable
}

Check a tutorial I've made with someone out [here](https://replit.com/talk/learn/2-C-Made-EZ/76981) for more! :D``````