nested for loop problem

I'm working on a program that asks for a mooses speed and a distance and the output should read the remaining distance that the moose has traveled every second

example:
Please enter the speed in m/s: 8
Please enter the distance in m: 57
The moose is 57m from its destination after 0 seconds
The moose is 49m from its destination after 1 seconds
The moose is 41m from its destination after 2 seconds
The moose is 33m from its destination after 3 seconds
The moose is 25m from its destination after 4 seconds
The moose is 17m from its destination after 5 seconds
The moose is 9m from its destination after 6 seconds
The moose is 1m from its destination after 7 seconds
The Goose has landed! Moo!


My program kind of works but has a slight glitch and doesn't quite put out the right output. Any help would be greatly appreciated. This is what my code looks like


int main()
{
int speed, distance;
do
{
cout << "Please enter the speed in M/S" << endl;
cin >> speed;
} while (speed <= 0);

do
{
cout << "Please enter the distance in M" << endl;
cin >> distance;
} while (distance <= 0);

for (int i = distance; i >= 1; i = i - speed)
{

for (int j = 0; j <= speed; j = j + 1)

{
cout << "The moose is" << i << "from its destination after" << j << endl;
}
}
cout << "The Goose Has Landed! Moo!" << endl;



system ("PAUSE");
return 0;
Where do you calculate remaining distance from speed?
I'm not sure exactly where to put what your saying?
cmpt 111?
I don't think you need a for loop. Try an if else
Yeah cmpt 111 U of S .... You?
same
You need exactly one for loop. Although there are multiple ways of writing it, I would suggest having
the loop count the number of elapsed seconds, beginning at 0. The loop's end condition is when the
moose has reached the destination.

Topic archived. No new replies allowed.