Unknown error
Aug 14, 2013 at 4:54pm UTC
I'm working on a program to simulate an elevator, and to stop my elevator from going upt to floors with no people, I have it check if all the other floors have a value of zero, and if they do, then that means to stay put. I just started to work on this when I got this error on line 132.
|132|error: lvalue required as left operand of assignment
Here is the code, if some one could help I would really appreciate it.
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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
[code][code]#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
srand(time(NULL));
//Random people on each floor
int people1 = rand()%3 + 1;
int people2 = rand()%3 + 1;
int people3 = rand()%3 + 1;
int people4 = rand()%3 + 1;
int people5 = rand()%3 + 1;
int currentPeople = 0;
//Sotores that button was pushed.
int pushed = 1;
//Up buttons outside the elevator
int Up1;
int Up2;
int Up3;
int Up4;
int Up5;
//Represnts all otheer floors emty
int empty = 0;
//Door Control
int Door;
int Open = 2;
//People in elevator?
int People;
int inElevator = 3;
//Keep track of current floor
int CurrentFloor;
//to end all loops
int x = 1;
//Simulate people calling elevator
//check floor 1
cout << "If floor one has someone on it, press one. If not, press 0." << endl;
cin >> Up1;
if (Up1 == pushed){
cout << "Floor one has been qued!" << endl;
}
//check floor 2.
cout << "If floor two has someone waiting, press one. If not, zero." << endl;
//did someone call on floor 2?
cin >> Up2;
// If so...
if (Up2 == pushed){
cout << "Floor two has been qued." << endl;
}
//check F3
cout << "If floor 3 has someone waiting press one. If not, press 0." << endl;
cin >> Up3;
if (Up3 == pushed){
cout << "Floor three has been qued" << endl;
}
//check F4
cout << "If someone is on Floor 4 press one. If not press 0" << endl;
cin >> Up4;
if (Up4 == pushed){
cout << "Floor 4 has been qued!" << endl;
}
//check F5
cout << "If someone is on Floor 5, press one. If not press 0." << endl;
cin >> Up5;
if (Up5 == pushed){
cout << "Floor 5 has been qued!" << endl;
}
//Pick Up System
if (Up1 == pushed){
cout << "Elevator has arrived on Floor One! Door opening!" << endl << endl;
Door = Open;
while (x < 250000000) {
x++;
}
x = 0;
cout << "Door has opened." << endl << endl;
CurrentFloor = 1;
cout << people1 << " people coming in." << endl << endl;
currentPeople = currentPeople + people1;
while (x < 250000000) {
x++;
}
x = 0;
cout << "There are now " << currentPeople << " on elevator" << endl << endl;
cout << "Door Closing!" << endl << endl;
Door = 1;
while (x < 250000000) {
x++;
}
}
x = 0;
if (Up2 + Up3 + Up4 + Up5 = empty){
cout << "Insert Logic here!" << endl;
}
//elevator rising
cout << "Elevator rising to next level." << endl << endl;
while (x < 350000000) {
x++;
}
x = 0;
if (Up2 == pushed){
cout << "Elevator has arrived on Floor Two! Door opening!" << endl << endl;
Door = Open;
while (x < 250000000) {
x++;
}
x = 0;
cout << "Door has opened." << endl << endl;
CurrentFloor = 2;
cout << people2 << " people coming in." << endl << endl;
currentPeople = currentPeople + people2;
while (x < 250000000) {
x++;
}
x = 0;
cout << "There are now " << currentPeople << " on elevator" << endl << endl;
cout << "Door Closing!" << endl << endl;
Door = 1;
while (x < 250000000) {
x++;
}
}
x = 0;
cout << "Elevator rising to next level." << endl << endl;
while (x < 350000000) {
x++;
}
x = 0;
if (Up3 == pushed){
cout << "Elevator has arrived on Floor Three! Door opening!" << endl << endl;
Door = Open;
while (x < 250000000) {
x++;
}
x = 0;
cout << "Door has opened." << endl << endl;
CurrentFloor = 3;
cout << people3 << " people coming in." << endl << endl;
currentPeople = currentPeople + people3;
while (x < 250000000) {
x++;
}
x = 0;
cout << "There are now " << currentPeople << " on elevator" << endl << endl;
cout << "Door Closing!" << endl << endl;
Door = 1;
while (x < 250000000) {
x++;
}
}
x = 0;
cout << "Elevator rising to next level." << endl << endl;
while (x < 350000000) {
x++;
}
x = 0;
if (Up4 == pushed){
cout << "Elevator has arrived on Floor Four! Door opening!" << endl << endl;
Door = Open;
while (x < 250000000) {
x++;
}
x = 0;
cout << "Door has opened." << endl << endl;
CurrentFloor = 4;
cout << people4 << " people coming in." << endl << endl;
currentPeople = currentPeople + people4;
while (x < 250000000) {
x++;
}
x = 0;
cout << "There are now " << currentPeople << " on elevator" << endl << endl;
cout << "Door Closing!" << endl << endl;
Door = 1;
while (x < 250000000) {
x++;
}
}
x = 0;
cout << "Elevator rising to next level." << endl << endl;
while (x < 350000000) {
x++;
}
x = 0;
if (Up5 == pushed){
cout << "Elevator has arrived on Floor Five! Door opening!" << endl << endl;
Door = Open;
while (x < 250000000) {
x++;
}
x = 0;
cout << "Door has opened." << endl << endl;
CurrentFloor = 5;
cout << people5 << " people coming in." << endl << endl;
currentPeople = currentPeople + people5;
while (x < 250000000) {
x++;
}
x = 0;
cout << "There are now " << currentPeople << " on elevator" << endl << endl;
cout << "Door Closing!" << endl << endl;
Door = 1;
while (x < 250000000) {
x++;
}
}
x = 0;
}
Aug 14, 2013 at 5:02pm UTC
The expression in the if statement
if(Up2 + Up3 + Up4 + Up5 = empty){
is invalid. You are trying to assign object empty to temporar expression
Up2 + Up3 + Up4 + Up5
Maybe you meant the comparison instead of assignment?
if(Up2 + Up3 + Up4 + Up5 == empty){
Aug 14, 2013 at 5:20pm UTC
I did mean the comparison. Thank you very much. I'm just thinking of the logic of my program and not taking a step back to look at the small details and errors. Thanks again for your help.
Topic archived. No new replies allowed.