Borad

This is a discussion on Borad within the C++ Programming forums, part of the General Programming Boards category; How do i put this in board? Code: #include <iostream> #include <iomanip> #include <fstream> #include <string> #include <cstdlib> #include <ctime> ...

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

    Borad

    How do i put this in board?


    Code:
    #include <iostream>
    #include <iomanip>
    #include <fstream>
    #include <string>
    #include <cstdlib>
    #include <ctime>
    
    using namespace std;
    
    const int size_x = 10;
    const int size_y = 10;
    
    int field[size_x][size_y];
    
    void board(int location [size_x][size_y], char direction);
    void ships(char carrier, char battleship, char cruiser, char submarine, char destroyer);
    
    int main ()
    {
    	char direction;
    	char name;
    	char proceed;
    
    	cout << "What shp do you want to place" << endl;
    	cout << "carrier = C "<< endl;
    	cout << "battleship = B "<< endl;
    	cout << "cruiser = R "<< endl;
    	cout << "submarine = S "<< endl;
    	cout << "destroyer = D \n";
    	cin >> name;
    	cout << endl;
    
    	do
    	{
    
    	switch (name)//switch statement
    	{
    	case 'c':
    	case 'C':	cout << "What coordinates do ya want for this ship ? ";
    	cin >> direction;
    	cout << endl;
    	direction = toupper(direction);
    		break;
    
    	case 'b':
    	case 'B':	cout << "What coordinates do ya want for this ship ? ";
    	cin >> direction;
    	cout << endl;
    	direction = toupper(direction);
    		break;
    
    	case 'r':
    	case 'R':	cout << "What coordinates do ya want for this ship ? ";
    	cin >> direction;
    	cout << endl;
    	direction = toupper(direction);
    		break;
    
    	case 's':
    	case 'S':	cout << "What coordinates do ya want for this ship ? ";
    	cin >> direction;
    	cout << endl;
    	direction = toupper(direction);
    		break;
    
    	case 'd':
    	case 'D':	cout << "What coordinates do ya want for this ship ? ";
    	cin >> direction;
    	cout << endl;
    	direction = toupper(direction);
    	break;
    
    	cout << "Do you want to continue:\n"
    		 << "y (yes) or n (no)";
    	cin >> proceed;
    	proceed ='y';
    	cout << endl;
    
    	default: cout << "Invalid letter." << endl;
    	}//end of switch
    	}
    	while(proceed != 'y');//end of loop
    
    	return 0;
    }
    void ships(char carrier, char battleship, char cruiser, char submarine, char destroyer)
     {
    
     }
    
    void location(int& size_x, int& size_y)
    {
    
    }

  2. #2
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Are you asking how to display it?

  3. #3
    Registered User
    Join Date
    Dec 2004
    Posts
    7
    yeah

  4. #4
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Convert your matrix of symbols your program can work with into a matrix of symbols your user will see. Then use cout to print your horizontal coordinates (separated by spaces - how many is up to you - in console I/O you usually can go up to 80 chars wide), and start a new line. Then perhaps draw a border of hyphens (-), and then a new line. And then start alternating between printing the pipe symbol (|) and the symbols from your matrix. On the next line, print some more hyphens for a horozontal separator, and keep the process going. On each line with symbols, print your vertical coordinates too.

    I'm sure this could be done with a loop, but for the sake of simplicity, I suggest you just use lots of cout statements - I think that's more fun anyway

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21