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. -
#include <stdio.h>
-
#include <stdlib.h>
-
#include <math.h>
-
#include "random.hpp"
-
-
int main(int argc, char* argv[]){
-
if (argc!=3) printf("please enter: shut <#tiles> <#games to run>\n");
-
int numTiles= atoi(argv[1]);
-
int numGames= atoi(argv[2]);
-
int tiles[numTiles];
-
int die1, die2, dietotal;
-
int score=0, highscore=0, lowscore=0, medianScoreTot=0;
-
-
printf("no tiles: %d, games: %d \n", numTiles, numGames);
-
-
-
for (int j=0;j<numTiles;j++){ //init the tiles: 0 is up, 1 is down
-
tiles[j]=0;
-
}
-
-
for (int i=0; i<numGames; i++){ //begin a new game
-
die1= randui(1, 6);
-
die2= randui(1, 6);
-
dietotal=die1+die2;
-
-
printf("die1: %d, die2: %d, total: %d \n", die1, die2, dietotal);
-
-
//*******************************************
-
//lowst firstfor (int k=1; k<dietotal+1;k++){
-
if (dietotal==2){
-
tiles[2]=1;
-
}else if (dietotal==3){
-
int rand= randui(1, 2);
-
if (rand==1){
-
tiles[3]=1;
-
}else tiles[1]=1 && tiles[2]=1; //**the ERROR comes here
-
}
-
-
else if (dietotal==4){ //*************
-
int rand= randui(1, 3);
-
if (rand==1){
-
tiles[4]=1;
-
}else if (rand==2){
-
tiles[3]=1 && tiles[1]=1; //**the ERROR comes here
-
}else tiles [2]=1;
-
}
-
-
else if (dietotal==5){ //*************
-
int rand= randui(1, 3);
-
if (rand==1)tiles[5]=1;
-
else if (rand==2) tiles[4]=1 && tiles[1]=1;
-
else tiles[3]=1 && tiles[2]=1; //**the ERROR comes here
-
}
-
else printf("there was an error. your sum was not 2-12\n");
-
-
}//end loooop for no games.
-
-
// print the tile array to see which were turned.
-
for (int l=1;l<numTiles+1 ;l++){ //init the tiles: 0 is up, 1 is down
-
printf("tile[%d]: %d /n", l, tiles[l]);
-
}
-
//****************
-
return 0;
-
}
-
-
1 2278
This doesn't make any sense. Why are you boolean ANDing 1 with tiles[2]?
I think you meant to do the assignment separately. - else {
-
tiles[3] = 1;
-
tiles[2] = 1;
-
}
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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:...
|
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;
|
by: Paul Edwards |
last post by:
The following code:
int main(void)
{
char *x;
(void **)x += 1;
return (0);
}
|
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("......");
|
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-...
|
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
...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
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...
| |