tags:

views:

107

answers:

4
include<iostream>

class Hanoi {

private: 
int n;// no. of disks

public: 
Hanoi(int); 
solve(char, char, char int); 
};

void Hanoi :: Hanoi(int a) {

cout << "Enter number of disks : " << endl; 
cin >> a; 
n = a; 
}

void Hanoi :: tower(char from, char use, char to) { 
if (n > 0) { 
tower(n-1, from, use, to); 
cout << "Move disk " << n << " from " << from << " to " << to); 
tower(n-1, use, to, from); 
} 
}

int main(void) 
{ Hanoi h = new Hanoi(); 
h.tower('A','B','C'); 
}
A: 

you need

using namespace std;

... and to read again the C++ specifications .... and you may get something like this:

#include<iostream>

using namespace std;

class Hanoi {
public: 
  Hanoi(); 
  void solve(int, char, char, char); 
};

Hanoi :: Hanoi() {
}

void Hanoi :: solve(int n, char from, char use, char to) { 
  if (n > 0) { 
    solve(n-1, from, use, to); 
    cout << "Move disk " << n << " from " << from << " to " << to << endl; 
    solve(n-1, use, to, from); 
   } 
}

int main(void) { 
  Hanoi h; 
  int N;
  cout << "Enter number of disks : " << endl; 
  cin >> N; 
  h.solve(N,'A','B','C'); 
}
fabrizioM
Good heavens, don't do the boy's homework for him. If he passes this class and eventually graduates, someone will eventually hire him without him having done his own work. Then where will our profession be?
Michael Todd
nah, if he does this job without enjoying the challenges, he will be miserable and quit to be an actor.
fabrizioM
I almost want to edit that all away. Doing his homework for him is counter productive.
Ed Swangren
he is way to far away from a correct solution. only frustration will come out of that = not studying = more posts on SO.
fabrizioM
+1  A: 

Constructors dont have a return type. Hanoi is your class and the following a constructor it need not have a void return type

void Hanoi :: Hanoi(int a)

should be

Hanoi :: Hanoi(int a)
Als
A: 

No guys it's not that. I'm not good at programming. I had a bad background with it. I am getting tutored on C++ from scratch. The homework s due tomorrow at 8:30 in the morning. It's just a little late and I needed this help. I tried it on my own and ended up with 6 errors.

Guess you should have paid more attention in class and studied harder then eh?
Ed Swangren
Hey! That's not your problem.
what you should have done was worked on this earlier and posted the errors that you got and asked for an explanation of why you got those error messages. That would have helped you out in the long run rather than asking for an answer to how to do your homework.
clyc
A: 

Why is everyone coming down on me like that? I needed help. I did not know this would be such a big idea. It is not like I can't go back and understand where I want wrong when my professor goes over it in class tomorrow. Everyone relax. I apologize for asking a question on this website, or shall I say requesting an answer. I thought this is what the website was for. Someone referred me to this website.

If the person who referred you to this website imparted to you that anyone here would be glad to do your homework for you, they were wrong. Anyone here will be glad to help you if they can, but almost everyone I've seen here will be _much_ more likely to help you if you've tried to help yourself and just need a little nudge.
Michael Todd