Hopscotch Help

Hey y'all I need help on a bit of my homework for class, and I'm just not understanding what I need to do.
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
  Write a function that swaps three numbers without using extra variables.
void swap (int &a, int &b, int c)
{
 //Fill me in
}
 Note: Do not call any other functions or use bitwise operations.
Write a C++ program to test a function called hopscotch() that accepts an integer number of hops as
its parameter and prints a pattern of numbers that resembles a hopscotch board. A hop is three-number
sequence where the output show two numbers on a line, followed by one number on its own line. 0 hops
is a board up to 1; one hop is a board up to 4; two hops is board up to 7, and so on. A call of
hopscotch(0) should only print the number 1. Output should look similar to below.
Sample Run:
Enter number of hops: 2
 1
2 3
 4
5 6
 7
Fill in the missing parts of the program below to solve the problem as stated above. Do not add any
additional lines of code. (10 @ 2 each)
//Hopscotch.cpp
#include <iostream>
_#include <iomanip>_ //1
using namespace std;
void hopscotch(int hops);
int main()
{
 int value;
 ____cout << "How many hops?" << endl;_ //2
 cin >> value;
 ________________ //3
 return 0;
}
void hopscotch(int hops) {
 for (int i = 1; i <= hops * 3 + 1; i++) {
if (i % 3 == 1)
 ________________________ //4
else if (______________) //5
 cout << setw(2) << i;
else
 cout << setw(4) << i << endl;
 }
}
7
Pre Test- This part has already been taken. Your score 


Thanks in advance! I'm not completely sure on the wording of the first problem...than the second one I just not sure where to go with...Thank you!
closed account (LNboLyTq)
1
2
3
4
5
6
void swap(int &a, int &b, int c)
{
    c = a;
    a = b;
    b = c;
}
Thank you so much! I understand what he was talking about now. Now I just need help with the hopscotch problem :)
Did you ever get help on the Hopscotch problem? Having issues w/ it as well :(
Yes I did his code that he posted was a little messed up.

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
27
28
29
30
31
32
33
34
 #include <iostream>
#include <iomanip> <---- this is for the setw

using namespace std;

void hopscotch (int hops);

int main ()
{

int value;

cout << "Enter your number of hops : " << endl;
cin >> value; // He should have made this hops and in the IDE it works with hops not value.

hopscotch (hops);

return 0;

}

void hopscotch (int hops)
{
for (int i=1; i <= hops *3 +1; i++)
{
if (i % 3 == 1)
cout << setw(0) << i;
else if(i==0)
cout << setw(2) << i;
else 
cout << setw(4) << i << endl;
}
}


I hope this helps, I wrote this code out so that I could see how it works instead of just seeing it on paper, and it gives you the right answer. It is just the fact that his variable is messed up.
Topic archived. No new replies allowed.