Thread: Knight's Tour: couting problems

  1. #1
    Registered User
    Join Date
    Dec 2003
    Posts
    7

    Knight's Tour: couting problems

    Hey, for some reason when I try and compile and build my code, it's giving me errors...
    NOTES: Spacing is odd only when I post the code on the message board
    Code:
    #include <iostream>
    
    using std::cin;
    using std::cout;
    using std::endl;
    
    int main()
    {
    	
    
    	cout << "The knight's tour requires a knight to touch every space on the chessboard." << endl;
    	cout << "Here is the solution to the knight's tour, each number represents a move." << endl;
    	cout << " -------------------------------------------------------------- " << endl;
    	cout << "|1		|24		|55		|36		|11		|22		|53		|34		|" << endl;	
    	cout << " -------------------------------------------------------------- " << endl;
    	cout << "|56	|37		|12		|23		|54		|35		|10		|21		|" << endl;	
    	cout << " -------------------------------------------------------------- " << endl;
    	cout << "|13	|2		|25		|64		|41		|60		|33		|52		|" << endl;	
    	cout << " -------------------------------------------------------------- " << endl;
    	cout << "|26	|57		|38		|61		|44		|63		|20		|9		|" << endl;	
    	cout << " -------------------------------------------------------------- " << endl;
    	cout << "|3		|14		|45		|42		|59		|40		|51		|32		|" << endl;	
    	cout << " -------------------------------------------------------------- " << endl;
    	cout << "|40	|27		|58		|39		|62		|43		|8		|19		|" << endl;	
    	cout << " -------------------------------------------------------------- " << endl;
    	cout << "|15	|4		|29		|48		|17		|6		|31		|50		|" << endl;	
    	cout << " -------------------------------------------------------------- " << endl;
    	cout << "|28	|47		|16		|5		|30		|49		|18		|7		|" << endl;	
    	cout << " -------------------------------------------------------------- " << endl;
    	cout << "The moves create a semi-symmetrical pattern around the board. << endl; 
    	cout << "The tour is completed with only four trips around the board. << endl;
    		
    	return 0;
    }
    here are my errors

    Code:
    knightstour.cpp(32) : error C2001: newline in constant
    knightstour.cpp(33) : error C2146: syntax error : missing ';' before identifier 'cout'
    knightstour.cpp(33) : error C2001: newline in constant
    knightstour.cpp(35) : error C2143: syntax error : missing ';' before 'return'
    Error executing cl.exe.
    Last edited by Sektor; 01-19-2004 at 08:30 AM.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >cout << "The moves create a semi-symmetrical pattern around the board." << endl;
    >cout << "The tour is completed with only four trips around the board." << endl;
    The errors tell you exactly what the problem is, that you are missing a double quote to close a string literal somewhere. They even tell you what lines the errors are near.

    >NOTES: Spacing is odd only when I post the code on the message board
    Tabs are evil, use spaces instead and you won't have this problem.
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Dec 2003
    Posts
    7
    Oh hehe, thanks. It came out that tabs are evil both on this message board and when executing my program. I fixed that part of it.
    Code:
    #include <iostream>
    
    using std::cin;
    using std::cout;
    using std::endl;
    
    int main()
    {
    	
    
    	cout << "The knight's tour requires a knight to touch every space on the chessboard." << endl;
    	cout << "Here is the solution to the knight's tour, each number represents a move." << endl;
    	cout << " ----------------------------------------------" << endl;
    	cout << "|1   |24   |55   |36   |11   |22   |53   |34   |" << endl;	
    	cout << " ----------------------------------------------" << endl;
    	cout << "|56  |37   |12   |23   |54   |35   |10   |21   |" << endl;	
    	cout << " ----------------------------------------------" << endl;
    	cout << "|13  |2    |25   |64   |41   |60   |33   |52   |" << endl;	
    	cout << " ----------------------------------------------" << endl;
    	cout << "|26  |57   |38   |61   |44   |63   |20   |9    |" << endl;	
    	cout << " ----------------------------------------------" << endl;
    	cout << "|3   |14   |45   |42   |59   |40   |51   |32   |" << endl;	
    	cout << " ----------------------------------------------" << endl;
    	cout << "|40  |27   |58   |39   |62   |43   |8    |19   |" << endl;	
    	cout << " ----------------------------------------------" << endl;
    	cout << "|15  |4    |29   |48   |17   |6    |31   |50   |" << endl;	
    	cout << " ----------------------------------------------" << endl;
    	cout << "|28  |47   |16   |5    |30   |49   |18   |7    |" << endl;	
    	cout << " ----------------------------------------------" << endl;
    	cout << "The moves create a semi-symmetrical pattern around the board." << endl; 
    	cout << "The tour is completed with only four trips around the board." << endl;
    		
    	return 0;
    }

  4. #4
    Registered User cyberCLoWn's Avatar
    Join Date
    Dec 2003
    Location
    South Africa
    Posts
    124
    If you want to use tab, use '\t' or even better, std::setw( size );

    Not forgetting

    Code:
    #include <iomanip>
    using std::setw;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. knight's tour!
    By Jasin14 in forum C Programming
    Replies: 13
    Last Post: 12-22-2010, 04:30 PM
  2. Knight's Tour Recursion Problem
    By thephreak6 in forum C++ Programming
    Replies: 1
    Last Post: 10-14-2003, 09:18 AM
  3. Knights Tour Trivia
    By shrestha in forum C++ Programming
    Replies: 2
    Last Post: 01-16-2003, 08:32 AM
  4. Knight's Tour Problem 2
    By Nutshell in forum C Programming
    Replies: 11
    Last Post: 01-09-2002, 09:32 PM
  5. Knight's Tour
    By Nutshell in forum C Programming
    Replies: 31
    Last Post: 01-08-2002, 10:58 PM