I have this funtion in my C program can someone please tell me what I'm doing wrong It seems to error out on compile on this section.
void PlaySparcMore(void)
{
int total, mark;
printf("\nPlaying SparcMore\n");
total = RollDice();
if (total == 7 || total == 11)
printf("You win 6 plumbats!\n");
else if (total == 3 || total == 5) {
printf("You lose 1 plumbat!\n");
else
mark = total;
printf("Your mark is %d.\n", mark);
while
total = RollDice();
if (total == mark)
printf("YOu hit your mark. You win 1 plumbat!\n");
break
else if (total == 3 || total == 5)
printf("Sorry you lose 1 plumbat!\n");
break;
}
C program code problems?
all modified lines have the comment "added" with a description of the modification.
void PlaySparcMore(void)
{
int total, mark;
printf("\nPlaying SparcMore\n");
total = RollDice();
if (total == 7 || total == 11)
printf("You win 6 plumbats!\n");
else if (total == 3 || total == 5) {
printf("You lose 1 plumbat!\n");
}// added line, forgot ending bracket
else
{// added line, forgot opening bracket
mark = total;
printf("Your mark is %d.\n", mark);
while (1)// added (1), put some condition here...
{// added line, forgot opening bracket
total = RollDice();
if (total == mark)
{// added line, forgot opening bracket
printf("YOu hit your mark. You win 1 plumbat!\n");
break;// added semicolon...
}// added line, forgot ending bracket
else if (total == 3 || total == 5)
{// added line, forgot opening bracket
printf("Sorry you lose 1 plumbat!\n");
break;
}// added line, forgot ending bracket
}// added line, forgot ending bracket
}// added line, forgot ending bracket
}
Reply:The Answer u got from both the person will give an error to u
if u want the answer just mail me the code i will get a back with a fare solution for it with in 2 minutes(including code ofmethod RollDice())
Reply:while / /while syntax should be like this while(condition)
total = RollDice();
if (total == mark) //after if u need 2 have brackets open and close after break and break should end with ;
printf("YOu hit your mark. You win 1 plumbat!\n");
break
else if (total == 3 || total == 5)
printf("Sorry you lose 1 plumbat!\n");
break;
}
Reply:The while condition must be within parantheses and in this case the body of the while loop must be within brackets
Also the break needs a semicolon (;) at the end
while(total = RollDice()) {
if (total == mark)
printf("YOu hit your mark. You win 1 plumbat!\n");
break;
else if (total == 3 || total == 5)
printf("Sorry you lose 1 plumbat!\n");
break;
}
Reply:aren't you missing something for your "while" statement... something like:
while (total != 3 || total != 5)
total = RollDice();
Other than that it could be in your "RollDice()" method.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment