What to modify on this code to make it working

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

What to modify on this code to make it working


#include <iostream>
using namespace std;
int
main ()
{
  int jumps, distance, loss = 1, counter,total_distance=0;
  cout << "Enter the distance: ";
  cin >> distance;
  cout << "How much it can jump: ";
  cin >> jumps;
  while (counter < jumps)
    {
      jumps -= 1;
      total_distance += jumps;
      counter++;
    }
  cout << "The distance: "<<total_distance;
  return 0;
}

A frog needs to jump to reach the swamp. The total distance it needs to cover is
given by the user. The jump distance that can be covered by the frog in each jump is
also given. After each jump, the jump distance is decreased by 1 because it loses
energy. Write a program to calculate and print the distance covered by the frog after
each jump and the total jumps needed to cover the total distance. See the given
sample of input/output. (hint: use while loop)
Sample Input/Output:
How much distance to cover: 53
How much distance to cover: 60
How much it can jump: 10
How much it can jump: 10
After jump #1 distance covered
After jump #2 distance covered
10
After jump #1 distance covered
After jump #2 distance covered
After jump #3 distance covered
After jump #4 distance covered = 34
After jump #5 distance covered
After jump #6 distance covered
After jump #7 distance covered = 49
After jump #8 distance covered = 52
After jump #9 distance covered = 54
After jump #10 distance covered =
The frog lost the energy before reaching the swamp
10
%3D
19
19
27
After jump #3 distance covered
After jump #4 distance covered =
After jump #5 distance covered =
After jump #6 distance covered
After jump #7 distance covered
After jump #8 distance covered
After jump #9 distance covered
The frog made it to the swamp after 9 steps
27
34
40
40
45
45
%3D
49
52
55
54
||D
|| || | |||
Transcribed Image Text:A frog needs to jump to reach the swamp. The total distance it needs to cover is given by the user. The jump distance that can be covered by the frog in each jump is also given. After each jump, the jump distance is decreased by 1 because it loses energy. Write a program to calculate and print the distance covered by the frog after each jump and the total jumps needed to cover the total distance. See the given sample of input/output. (hint: use while loop) Sample Input/Output: How much distance to cover: 53 How much distance to cover: 60 How much it can jump: 10 How much it can jump: 10 After jump #1 distance covered After jump #2 distance covered 10 After jump #1 distance covered After jump #2 distance covered After jump #3 distance covered After jump #4 distance covered = 34 After jump #5 distance covered After jump #6 distance covered After jump #7 distance covered = 49 After jump #8 distance covered = 52 After jump #9 distance covered = 54 After jump #10 distance covered = The frog lost the energy before reaching the swamp 10 %3D 19 19 27 After jump #3 distance covered After jump #4 distance covered = After jump #5 distance covered = After jump #6 distance covered After jump #7 distance covered After jump #8 distance covered After jump #9 distance covered The frog made it to the swamp after 9 steps 27 34 40 40 45 45 %3D 49 52 55 54 ||D || || | |||
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY