473,395 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

invalid lvalue in assignment... Shut the Box Program

Hi, am trying to program Shut the Box (http://en.wikipedia.org/wiki/Shut_the_Box). when I decide which tile to flip, I get the error " invalid lvalue in assignment". I've looked this up and it's usually because you need == instead of =, but I am assigning the value 1 to the array element... So I can't figure it out.... I will take some of it out so you can read it easier.

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include "random.hpp"
  5.  
  6. int main(int argc, char* argv[]){
  7.   if (argc!=3) printf("please enter: shut <#tiles> <#games to run>\n");
  8.  int numTiles= atoi(argv[1]);
  9.  int numGames= atoi(argv[2]);
  10. int tiles[numTiles];
  11. int die1, die2, dietotal;
  12. int score=0, highscore=0, lowscore=0, medianScoreTot=0;
  13.  
  14.  printf("no tiles: %d, games: %d \n", numTiles, numGames);
  15.  
  16.  
  17. for (int j=0;j<numTiles;j++){ //init the tiles: 0 is up, 1 is down
  18. tiles[j]=0;
  19. }
  20.  
  21. for (int i=0; i<numGames; i++){ //begin a new game
  22. die1= randui(1, 6);
  23. die2= randui(1, 6);
  24. dietotal=die1+die2;
  25.  
  26.  printf("die1: %d, die2: %d, total: %d \n", die1, die2, dietotal);
  27.  
  28. //*******************************************
  29. //lowst firstfor (int k=1; k<dietotal+1;k++){
  30.  if (dietotal==2){
  31. tiles[2]=1;
  32.  }else if (dietotal==3){
  33. int rand= randui(1, 2);
  34.   if (rand==1){ 
  35.     tiles[3]=1;
  36.   }else tiles[1]=1 && tiles[2]=1;  //**the ERROR comes here
  37.  }
  38.  
  39.  else if (dietotal==4){ //************* 
  40. int rand= randui(1, 3);
  41.   if (rand==1){ 
  42.     tiles[4]=1;
  43.   }else if (rand==2){
  44.  tiles[3]=1 && tiles[1]=1;  //**the ERROR comes here
  45.   }else tiles [2]=1;  
  46. }    
  47.  
  48.  else if (dietotal==5){ //************* 
  49. int rand= randui(1, 3);
  50.   if (rand==1)tiles[5]=1;
  51.  else if (rand==2) tiles[4]=1 && tiles[1]=1; 
  52.  else tiles[3]=1 && tiles[2]=1;   //**the ERROR comes here
  53.  }
  54.  else printf("there was an error. your sum was not 2-12\n");
  55.  
  56. }//end loooop for no games.
  57.  
  58. // print the tile  array to see which were turned.
  59. for (int l=1;l<numTiles+1 ;l++){ //init the tiles: 0 is up, 1 is down
  60.   printf("tile[%d]: %d /n", l, tiles[l]);
  61. }
  62. //****************
  63.  return 0;
  64. }
  65.  
  66.  
May 2 '13 #1
1 2278
Rabbit
12,516 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. tiles[3]=1 && tiles[2]=1
This doesn't make any sense. Why are you boolean ANDing 1 with tiles[2]?

I think you meant to do the assignment separately.
Expand|Select|Wrap|Line Numbers
  1. else {
  2.    tiles[3] = 1;
  3.    tiles[2] = 1;
  4. }
May 2 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

19
by: Lucas Machado | last post by:
i'm doing some Linux Kernel hacking for a course i'm currently taking. there is a pointer to a struct (struct example_struct *ex_ptr) in a .c that i want to access in a system call. i defined a...
4
by: bob | last post by:
I have little C experience and am concurrently trying to tackle C and LKM's (a little too ambitious maybe) anyway here is the problem I'm having with an example module I found. static int...
5
by: A. Farber | last post by:
Hello, I call readv() and writev() in several spots of a program which I run under Linux, OpenBSD and Cygwin. Since it always the same way (check the return value; then check errno and retry if...
1
by: Java Guy | last post by:
I'm trying to view a web page. IE tells me there are (Java?) errors on the page. Here they are: Line: 15 Char: 7 Error: Wrong number of arguments or invalid propert assignment Code: 0 URL:...
3
by: Suyash Upadhyay | last post by:
Hello all, I was writing a code regarding offset of structure elements. struct a { struct b { int i; float f; char ch; }x;
6
by: Paul Edwards | last post by:
The following code: int main(void) { char *x; (void **)x += 1; return (0); }
4
by: mdh | last post by:
May I ask why this works: given: char s; char *posbfr = s; char *endbfr = s + MAXOP; void(...){ if (posbfr >= endbfr) printf("......");
3
by: vunet | last post by:
Hello, I've just installed ASPXMLRPC library and testing their main function: xmlRPC ("URL", "command_name", params) The function converts all parameters to XML, sends a request to third-...
1
by: yyhkitty | last post by:
Hi, I keep getting two invalid lvalue in assignment errors. here's what my code looks like: pthread_t msg_receive(char *sbuffer, int *maxlen) { // get the values for sbuffer and maxlen ...
11
by: markryde | last post by:
Hello, Followed here is a simplified code example of something which I try to implement; in essence , I want to assign a value to a return value of a method is C. I know, of course, that in this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.