0

how would i get the file below to display the number of moves by adding an output statement
after the call to move() in main() to display the value of moveNumber, which will be the number of the last move. Thanks!

#include <iostream>
#include <iomanip>
#include "timer.h"
using namespace std;

void move(unsigned n, unsigned & moveNumber,
char source, char destination, char spare);

int main()
{
Timer t;

const char PEG1 = 'A', // the three pegs
PEG2 = 'B',
PEG3 = 'C';
unsigned moveNumber = 0; // counts the moves

cout << "This program solves the Hanoi Towers puzzle.\n\n";
cout << "Enter the number of disks: ";
unsigned numDisks; // the number of disks to be moved
cin >> numDisks;
cout << endl;
t.start();
move(numDisks, moveNumber, PEG1, PEG3, PEG2); // the solution
t.stop();
cout << "The number of seconds processing was" <<
t << endl;
}

Edited by react05: n/a

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Fbody
0

would it be

cout << "The number of moves to solve this was" << moveNumber << endl;

or would i have to do something else?

0

Since moveNumber is a reference parameter, you should just be able to simply add a line to main(), immediately after the call to move(), that outputs moveNumber just like any other output sequence.

0

would it be

cout << "The number of moves to solve this was" << moveNumber << endl;

or would i have to do something else?

moveNumber is a reference parameter, that should do it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.