conflict with previous decleration

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
#include <iostream>
#include <stdlib.h>

using namespace std;

//FP
int get_rand();
string get_figname(int);
int loop_check(bool fig[],int record,int randnum);

//begin of main
int main(int argc, char *argv[])
{
    //dec var
    int record = 0,total =0,randnum;
    string figname;
    bool fig[6];
    //start loop
    while(record != 6)
    {
        randnum = get_rand();
        figname = get_figname(randnum);
        total++;
        //print out
        cout<<total<<figname<<endl;
        //if the condition change form false to true add 1
        record = loop_check(fig,record,randnum);
    }    
    cout<<"the simulation have ran "<<total<<" time"<<endl;    
        
    
  
  system("PAUSE");	
  return 0;
}
//end of main

//generate random number
int get_rand()
{
    int num;
    srand(time(NULL));
    num = rand()%6;      
    return num;
} 

//get action fig name
string get_figname(randnum)
{
    switch (randnum)
    case 0:return ". Beet Farmer";
    case 1:return ". Bark Harvest";
    case 2:return ". turnip PUller";
    case 3:return ". Sugar Kettle Tender";
    case 4:return ". Box Filler";
    case 5:return ". Payroll Guard";
}  

//check record
int loop_check(bool fig[],int record[],int randnum)
{
    if (fig[randnum] == false)
    {
        fig[randnuum] = true;
        return record++
    }
    else
    return record;
}        


those are my code and this is the error message i got

line 48 std::string get_figname redeclared as different kind of symbol
line 8 previous declaration of 'std::string get_figname[int]'
line 48 declaration of "std::string get_figname"
line 8 conflict with previous declartion "std::string get_figname[int]"

i have no idea y im keep getting this error.
You declared get_figname as a function that takes an int and returns a string (line 8)
In your definition however the type of argument is not written so the compiler is confused.
On line 48, you are creating a function called get_figname that returns a string and accepts an object of type randnum.

I suspect you actually want it to accept an object of type int called randnum.

Edit: Beaten to the punch again by the Hamsterman. Part man, part hamster, all programmer. :)
Last edited on
thanks bunch problem solved :)
Topic archived. No new replies allowed.