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!
#include <iostream>
#include <iomanip> <---- this is for the setw
usingnamespace 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;
elseif(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.