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;
}

Recommended Answers

All 3 Replies

would it be

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

or would i have to do something else?

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.