error: expected unqualified-id before '.' token

I am creating a bee hive simulator for my class hw, and I'm running into a few errors. Here is my code so far.

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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* 
 *
 */

#include <cstdlib>
#include <iostream>
#include <cmath>
//need these for atoi function
#include <stdio.h>
#include <stdlib.h>
#include <functional>

using namespace std;

//to create a class
class bee_pop
{
public:
    float Pollen;
    float Nectar;
    float Water;
    float Propolis;
    int Workers;
    int Foragers;
    int Nurse;
    int Gaurd;
    int simday;

    //methods
public:
    float bees_start();
    float total_bees();
    
};

float bee_pop::bees_start()
{
 float Pollen = 0.0, Nectar = 0.05, Water = 0.0, Propolis = 0.0;
 int simday=1;
 float Workers = 8;
 
}

float bee_pop::total_bees()
{
     float Forager=0, Nurse=0, Gaurd=0, queen=1;
     int x,y;
     x = ((Workers*0.65)%100)/100.0;
     y = ((Workers*0.35)%100)/100.0;
     Forager = Workers*0.65;
     Nurse = Workers*0.35;
     Gaurd = x +y;
    
}

//**************************************************************
int main(int argc, char** argv)
{
    char command[20];
    bee_pop bees_start;  
    bee_pop total_bees;
   
    float Tot_Pollen=0.0,Tot_Nectar=0.0,Tot_Water=0.0,Tot_Propolis=0.0;
    int simday;
    
    
       
            cout << ")8( The Hundred-Acre Apiary Hive Simulator )8( \n";
            
            do 
            {
            cout << "Enter Command: \n";        
            cin >> command[0];

            if (command[0] == '?')
            {
                switch(command[1])
                {
                  case '?':
                      cout << "Error: Operand to ? command must be one of (FTW)."<<endl;
                      break;
                              
                  case 'T':
                      cout << "It is sim-day " << simday << "." << endl;
                      break;
                  case 'W':
                      bee_pop.total_bees();
                      break;                                
                    default:
                     cout << "Error: ? command required 1 operand." <<endl;
                }    
                               
            }
            
       
            if (command[0] == 'T')
            {
                simday = simday++;
            }
            if (command[0]== 'W' && command[1] == '+')
            {
                //this points to the 3rd element of the array and turns it into a number
                char* numStr = &command[2];
                int num = atoi(numStr);
                bee_pop.total_bees(num);
                //need to add the number to the workers
                
            }
            if (command[0] == 'W' && command[1] == '-')
            {
                char* numStr = &command[2];
                int num = atoi(numStr); 
                bee_pop.total_bees(num);
            }
            
            } //end of do loop
            
            while(command[0] == 'X'); 
            {
                cout<< "#" <<endl;
                return 0;         
            }
    

            return 0;
            
}


And here are the errors, that I am recieving.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
g++     hw4.cpp   -o hw4
hw4.cpp: In member function 'float bee_pop::total_bees()':
hw4.cpp:51:26: error: invalid operands of types 'double' and 'int' to binary 'operator%'
      x = ((Workers*0.65)%100)/100.0;
                          ^
hw4.cpp:52:26: error: invalid operands of types 'double' and 'int' to binary 'operator%'
      y = ((Workers*0.35)%100)/100.0;
                          ^
hw4.cpp: In function 'int main(int, char**)':
hw4.cpp:90:30: error: expected unqualified-id before '.' token
                       bee_pop.total_bees();
                              ^
hw4.cpp:108:24: error: expected unqualified-id before '.' token
                 bee_pop.total_bees(num);
                        ^
hw4.cpp:116:24: error: expected unqualified-id before '.' token
                 bee_pop.total_bees(num);
                        ^
make.exe": *** [hw4] Error 1

BUILD FAILED (exit value 2, total time: 1s)
 


Any help would be appreciated.
Last edited on
The modulo operator (%) only works on integers, which covers your first two errors.

Secondly, you try to call a function on a class, not your object.
1
2
bee_pop bees_start;
bee_pop total_bees;

These are your two objects of the bee_pop class. You will want to call total_bees() on either of those.
Last edited on
Topic archived. No new replies allowed.