loop program

I really need some assistance

[# include <iostream>

using namespace std;

int main()
{
int total,n,sum=0,counter=0,x;



cout<<"Enter total distance: ";
cin>>total;

x=(total/20);
cout<<"Distance of first jump <="<<x<<" "<<":"<<" ";
cin>>n;
cout<<endl;


if (n<=x)
{



while (counter<=total)


}


else
cout<<"incorrect first jump distance, setting first jump distance to: "<<x<<endl;




return 0;
}]
1) Input a positive integer total that represents the total distance in meters a person needs to travel.
2) Input a positive integer first that represents the distance of the first jump. This distance should be less than or equal to total/20. If first is greater than total/20 then set it to total/20.
3) Using a loop, calculate how many jumps are needed to cover the total distance. After every jump, the person jumps 1 meter more than the previous jump.

i need help with generating the loop.
[/code]
Think. What should happen on one jump?
Use code tags

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
int main(){

int total, jump;

std::cout << "Enter the total distance required to travel: ";
std::cin >> total;
std::cout << "\nEnter the distance that represents the first jump: ";
std::cin >> jump;

if(jump > total/20)
jump = total/20;

for (int i = 0; jump + i <= total; i++)
std::cout << ""; //Sorry about this but I'm writing it quick

std::cout << "You need " << i << " jumps to cover the total distance entered";

return 0;
}


Here you go. Just use the for loop (I haven't tested this so I'm not 100% sure it works, just 99.9%)

So solved?
Actually for line 25, you need to output i+1
Sorry. What post is your answer meant for? Because in my code there isn't any line 25 and in the OP's post he isn't using any variable named i
when i run the program it says that there is proplem in line 17
which is ((( error: name lookup of 'i' changed for ISO 'for' scoping ))
can u solve it plzzzz
Variables declared within the loop do not exist outside of the loop. Older C++ had longer lifetime.
This:
1
2
3
4
for (int i = 0; jump + i <= total; ++i)
std::cout << "";

std::cout << i; // error 

is same as this:
1
2
3
4
5
6
for (int i = 0; jump + i <= total; ++i)
  {
    std::cout << "";
  }

std::cout << i; // error 

is same as this:
1
2
3
4
5
6
7
8
9
{
  int i = 0;
  for ( ; jump + i <= total; ++i)
    {
      std::cout << "";
    }
} // end of scope, where the i exists
// there is no i any more
std::cout << i; // error 

Therefore:
1
2
3
4
5
6
7
int i = 0;
for ( ; jump + i <= total; ++i)
  {
    std::cout << "";
  }

std::cout << i; // ok 

really thanks guys i appreciate your efforts
thnks a lot again
Topic archived. No new replies allowed.