#Help formatting a for loop.

16 messages · Page 1 of 1 (latest)

near marsh
#

Hi everyone, I am currently working on a project for my c++ class, and need a little help formatting a for loop for what I am trying to do. Thank you all in advance! (I will be posting my code and what it is supposed to do in the comments)

sand pelicanBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

near marsh
#

what i have written as of right now

#

what it should look like when I am done

zinc nova
sand pelicanBOT
# zinc nova !sc
Eisenchan
Please Do Not Send Screenshots!

They're hard to read and prevent copying and pasting.

near marsh
#

whats the command for pasting the code in discord style

zinc nova
#

and to align things nicely, you're most likely looking for std::setw

sand pelicanBOT
#
How to Format Code on Discord
Markup

```cpp
int main() {}
```

Result
int main() {}
near marsh
#

oh wrong one

peak cometBOT
#
Critical error:

Unable to find a codeblock to format!

near marsh
#
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
    //program code goes here
    int startingPop;
    int increase;
    int days;
    int day;

    cout << "Lovebug Population Estimator\n\n";
    cout << "Enter the starting number of lovebugs:  ";
    cin >> startingPop;
    if (startingPop < 2)
    {
        cout <<
    }
    cout << "\nEnter the average daily percent increase (%):  ";
    cin >> increase;
    increase = increase / 100;
    cout << "\nEnter the number of days to multiply:  ";
    cin >> days;
    cout << "\n\nDay\tPopulation\n";
    for (day = 1; day <= days; day++);
    {
        cout << day << "\n";
    }
    system("pause");
    return 0;
}
#

i also changed that first if statement to be able to validate input better and not break the program haha

#
for (day = 1; day <= days; day++);
    {
        cout << day << "\n";
    }
#

how would i get this to print out like 1, 2, 3, 4...etc until it hits "days" which would be a user input anywhere from 1 to inf?

near marsh
#

!solved