While loops help!!

Writing a code to increase by 10% with each iteration. I can't figure out how to though. Also after 5 iterations I need to display a message. I'm at a loss.

This is what I have so far.

int main ()
{
double min_power = 10.2;
double max_power = 100.3;


cout << "Hi there my name is Butterfly Girl" << endl;
cout << "My superpower is to turn my body into numerous butterflies" << endl;
cout << "allowing me to infiltrate and find information on enemies." << endl;
cout << "But with this power comes an alarming weakness. Flowers." << endl;
cout << "Once in butterfly form any time I come across a flower I must" << endl;
cout << "land on it causing my enemies to easily trap me." << endl;

while (min_power <= max_power)
{
cout << "You're going to be in trouble soon I'm powering up." << endl;
min_power++;
{
if (min_power >= max_power)
cout << "Ahhh thats better time to take you down!" << endl;
}
}
return 0;
}
If i did not misunderstood this:

You want to print "you are going to..." every 5 iterations and increase the minimum power by 10%.

Then i dont know if this is will work or it is not what u want.

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
#include <iostream>
using namespace std;

int main () {
	double min_power = 10.2;
	double max_power = 100.3;


	cout << "Hi there my name is Butterfly Girl" << endl;
	cout << "My superpower is to turn my body into numerous butterflies" << endl;
	cout << "allowing me to infiltrate and find information on enemies." << endl;
	cout << "But with this power comes an alarming weakness. Flowers." << endl;
	cout << "Once in butterfly form any time I come across a flower I must" << endl;
	cout << "land on it causing my enemies to easily trap me." << endl;

	for( int i=0; min_power<=max_power; ++i) {   
		min_power = min_power + (min_power*0.1);
		if( i==5 ) {
			cout << "You're going to be in trouble soon I'm powering up." << endl;
			i=0;
		}
	}
	if (min_power >= max_power) {
		cout << "Ahhh thats better time to take you down!" << endl;
	}
}


I edited this, adding the condition that if i reaches 5, reassigns to value 0, but i dont know if thats the way beacuse im starting with c++...
Last edited on
The exact wording of the question is this:

Use a loop to power up your super hero’s abilities. Your super hero will start out with an ability score of 10.2. Each iteration of the loop will power up your character by 10%.
When it reaches 100.3. your character is powered up. Notice, the loop doesn’t stop on an
even boundary. So you will exit the loop when the ability is greater than equal to 100.3.
In each iteration of the loop will display a message of power up amount and some text
indicating what the number means. Once after 5 iterations through the loop, your super
hero will let slip what their weakness is in the form of text to be displayed on the screen.

im stumped...
So it almost works but it only reiterates 5 times and it needs to go at least 10. also at 5 I tell its weakness. but when I run what it is now it just comes up as after 5 It prints the powered up line.
So I need it to go from i==5, print a line about weakness, to run another 5 times. and It looks like with each line I need to put what i is.
Wow that wording it is difficult to understand. The 10% step is done, every iteration it powers up a 10%. The message when the power is greater than max power it is done too. I executed the program did before and it prints this (that it is what i understood):
Hi there my name is Butterfly Girl
My superpower is to turn my body into numerous butterflies
allowing me to infiltrate and find information on enemies.
But with this power comes an alarming weakness. Flowers.
Once in butterfly form any time I come across a flower I must
land on it causing my enemies to easily trap me.
You're going to be in trouble soon I'm powering up.
You're going to be in trouble soon I'm powering up.
You're going to be in trouble soon I'm powering up.
You're going to be in trouble soon I'm powering up.
Ahhh thats better time to take you down!


If you could explain this better, i do not understand it at all...btw, with the program i sent yesterday, can't you try to see how that works and type the variable that you want to do?

In each iteration of the loop will display a message of power up amount and some text
indicating what the number means. Once after 5 iterations through the loop, your super
hero will let slip what their weakness is in the form of text to be displayed on the screen.

im stumped...
So it almost works but it only reiterates 5 times and it needs to go at least 10. also at 5 I tell its weakness. but when I run what it is now it just comes up as after 5 It prints the powered up line.
So I need it to go from i==5, print a line about weakness, to run another 5 times. and It looks like with each line I need to put what i is.
Topic archived. No new replies allowed.