Treasure Hunt program (arrays) help

In a 5 by 5 board, the user must type in x and y coordinates (e.x 4,5) for treasure, specifically 10 treasures out of the possible 25 board spaces.There is a board before the program start which will randomly select coordinates that will act as treasure spots. The program will basically run until you have found all 10 treasures. The only problem is that my instructor has not been here the last week, so i only know that i am using [srand(time(null))] and two different 2 dimensional arrays. I would really appreciate it if you guys could point me in the right direction. TY in advance.

Important: each square on the board has a # covering it. if there is a treasure there, a $ is revealed. If there is nothing thee, simply a blank space
Last edited on
What have you got so far? Have you created the board?
Right now i am trying to find out what kinds of functions and loops i made need in order to complete the program.
Right now i am having trouble with the input of these coordinates and the output of the solution board.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>

using namespace std;

void display(char board[5][5]){
cout<<" | 1 | 2 | 3 | 4 | 5 |"<<endl;
for(int x=0;x<5;x++)
{
cout<<     " ____________________"<<endl;
cout<<x+1<<"| # | # | # | # | # |"<<endl;
   // for(int y=0;y<5;y++){
//cout<<y+1
   // }
    }
cout<<"  ___________________"<<endl;
    }
void initialBoard(char SolutionBoard[5][5],int gold)
{   gold=0;
    while(gold<10){

        int a=rand()%5;
        int b=rand()%5;
        if(SolutionBoard[a][b]!='$'){
        SolutionBoard[a][b]='$';
        gold++;


        }
        }
}
void characters(char fill[5][5]){
    for(int c=0;c<5;c++){
        for(int d=0;d<5;d++){
            fill[c][d]='#';
        }
    }
}
int main(){
    char fill[5][5];
    char board[5][5];
    char SolutionBoard[5][5];
    int gold;
    srand(time(NULL));
    characters(fill);
    display(board);
    cout<<endl;
    initialBoard(SolutionBoard,gold);
    display(SolutionBoard);

    return 0;
}
i finished. Here is the code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <iostream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
int ans1,ans2;
int q=0;
int w=0;
int u=0;
int x;
int y;
int n1,n2;

void bboard(char board[5][5]){//outputs screen board
 cout<<" ------------"<<endl;
        cout<<"| |1|2|3|4|5|";
        //cout<<"1";
            int linendernum=0;
      for(int y=0;y<5;y++){ //loops that outputs the first board
            cout<<endl;
            cout<<" ------------"<<endl;
             linendernum++;
             cout<<"|";
                cout<<linendernum;
                cout<<"|";
        for(int x=0;x<5;x++){
            cout<<board[x][y];
            cout<<"|";
        }//2nd for loop bracket
      }//for loop bracket
      cout<<endl;
      cout<<" ------------"<<endl;
}
void cboard(char mboard[5][5]){//outputs mboard
     int linendernum2=0;
        cout<<" ------------"<<endl;
        cout<<"| |1|2|3|4|5|";
        //cout<<"1";
      for(int q=0;q<5;q++){ //loops that outputs the board with the dollars
            cout<<endl;
            cout<<" ------------"<<endl;
             linendernum2++;
             cout<<"|";
                cout<<linendernum2;
                cout<<"|";
        for(int w=0;w<5;w++){
            if(mboard[w][q]!='$'){
                mboard[w][q]='#';
            }
            cout<<mboard[w][q];
            cout<<"|";
        }
        }
      cout<<endl;
      cout<<" ------------"<<endl;
}
void randomizer(char mboard[5][5]){//the randomizer for gold
    int gold=0;
    int n1,n2;
    while(gold<10){//-------------------------------------------------------------------------------end of the randomizer loop/beggining of the mboarsd loop
        int n1=rand()%5;
        int n2=rand()%5;
        if(mboard[n1][n2]!='$'){
            mboard[n1][n2]='$';
            gold++;
        }
        }
}
void guessing(char board[5][5],char mboard[5][5]){
    int win=0;
     do{
            cout<<"Enter first coordinate";
            cin>>ans1;
            cout<<"Second cord";
            cin>>ans2;
            if(mboard[ans1-1][ans2-1]=='$'){
                board[ans1-1][ans2-1]='$';
                cout<<"You gone one gold!"<<endl;
                win++;
            }
            else{
                 board[ans1-1][ans2-1]=' ';
                 cout<<"Better luck next time....."<<endl;
                       }
            bboard(board);
     }while(win!=10);
}

int main(){
    srand(time(NULL));
    char board[5][5]={'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'};
    char mboard[5][5];

    cout<<"Hello, Welcome to TREASURE HUNT!!"<<endl;

    bboard(board);
    randomizer(mboard);
    cboard(mboard);
    guessing(board,mboard);

    cout<<"Nice Job!";

      return 0;
}
Topic archived. No new replies allowed.