Question

Can someone let me know what to do for this? In C Programming.

HERE ARE INSTRUCTIONS:

it is for a yahtzee game program.

Write function sumChance to do the following a. Return type int b. Parameter list array of dice c. Declare int variable sum d

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/******************************************************************************

Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/
#include <stdio.h>
int sumchance(int dice[]);
int checklgstraight(int dice[]);
int sortdice(int dice[]);
int main()
{
int sum ;
int dice[] = {99, 90, 96, 93, 95};
sum = sumchance(dice); // name of the array is passed as argument.
  
printf(" %d", sum);
  
sum=checklgstraight(int dice[]);
  
printf(" %d", sum);
return 0;
}

int sumchance(int dice[])
{
int i, sum = 0;
  
for (i = 0; i <= 4; i++) {
sum += dice[i];
}
  
return sum;
}

int checklgstraight(int dice[]){
int sum=0;
sum= sortdice(dice);
return sum;
}

int sortdice(int dice[]){
int size=sizeof(dice) / sizeof(dice[0]);
int i,j,a;int sum=0;
int flag1=0;int flag2=0;
int dice1[]={1,2,3,4,5};
int dice2[]={2,3,4,5,6};
for (i = 0; i < n; ++i)
{

for (j = i + 1; j < n; ++j)
{

if (dice[i] > dice[j])
{

a = dice[i];
dice[i] = dice[j];
dice[j] = a;

}

}

}
sub: for( i=0 ;i<n ;i++){
if(dice[i]!=dice1[i])
{
flag1=1;
break sub;
}
}
  
sub1: for( i=0 ;i<n ;i++){
if(dice[i]!=dice2[i])
{
flag2=1;
break sub;
}
}
  
if(flag1==1||flag2==1){
return 0;
}
else{
return 40;
}
  
  
}

Add a comment
Know the answer?
Add Answer to:
Can someone let me know what to do for this? In C Programming. HERE ARE INSTRUCTIONS:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Can someone let me know what to do for this? In C Programming. HERE ARE INSTRUCTIONS:...

    Can someone let me know what to do for this? In C Programming. HERE ARE INSTRUCTIONS: Write function sum Category to do the following a. Return type int b. Parameter list i. int array dice ii. int value category c. Declare int variable sum d. Declare int variable die e. Loop through the dice array i. Based on the selected category check if the value of the current die matches the category (i.e. user selected ONE for category, die value...

  • Can someone let me know what to do for this? In C Programming. HERE ARE INSTRUCTIONS:...

    Can someone let me know what to do for this? In C Programming. HERE ARE INSTRUCTIONS: Here is my code I have that needs to be edited with instructions. : void displayUpperSection(int scoreCard[CATEGORIES][COLS]){ printf("+-----------------|-----------|\n"); printf("+ UPPER SECTION | SCORE |\n"); printf("+-----------------|-----------|\n"); printf("+ ONEs | %d |\n", scoreCard[one][COL]); printf("+-----------------|-----------|\n"); printf("+ TWOS | %d |\n", scoreCard[two][COL]); printf("+-----------------|-----------|\n"); printf("+ THREES | %d |\n", scoreCard[three][COL]); printf("+-----------------|-----------|\n"); printf("+ FOURS | %d |\n", scoreCard[four][COL]); printf("+-----------------|-----------|\n"); printf("+ FIVES | %d |\n", scoreCard[five][COL]); printf("+-----------------|-----------|\n"); printf("+ SIXES | %d...

  • Can someone let me know what to do for this? In C Programming. HERE ARE INSTRUCTIONS:...

    Can someone let me know what to do for this? In C Programming. HERE ARE INSTRUCTIONS: This is my code for that specific section: void displayScoreCard(int scoreCard[CATEGORIES][COLS]) { printf("\n\n\t\tYAHTZEE SCORECARD\n"); displayUpperSection(scoreCard); displayLowerSection(scoreCard); printf("\t\t+-------------+-------------+\n\n"); printf("+-----------------|-----------|\n"); printf("+ TOTAL (Upper) | %d |\n", ZERO); printf("+-----------------|-----------|\n"); printf("+ GRAND TOTAL | %d |\n", ZERO); printf("+-----------------|-----------|\n\n\n"); } Update function displayScoreCard to do the following a. Declare local variable total set equal to the result from function call sumUpper and checkBonus b. Declare local variable grandTotal set...

  • Write a Python (version 3.5.2) program that simulates how often certain hands appear in Yahtzee. In...

    Write a Python (version 3.5.2) program that simulates how often certain hands appear in Yahtzee. In Yahtzee, you roll five dice and then use those dice to make certain combinations. For example, the Yahtzee combination is formed by all five dice having the same value. A large straight occurs when all of the dice are in consecutive order (e.g., 1,2,3,4,5 or 2,3,4,5,6). If you haven’t played Yahtzee, you can find out more from various online sources such as Wikipedia. Once...

  • "Controlling complexity is the essence of computer programming." Write a program that uses the C++ string...

    "Controlling complexity is the essence of computer programming." Write a program that uses the C++ string functionality to count the number of vowels in this phrase. Q7. Write a function bool xor(bool A, bool B) which returns the Exclusive OR of boolean input variables A and B. Test your function by printing out the full truth table of the function. Q8. Write a method swap(char_all, int i, int i) which swaps element i and element j of a given character...

  • 1. Write a statement that calls a function named showSquare, passing the value 10 as an...

    1. Write a statement that calls a function named showSquare, passing the value 10 as an argument. 2. Write the function prototype for a function called showSquare. The function should have a single parameter variable of the int data type and areturn type of void. 3. Write the function prototype for a function called showScoreswith a parameter list containing four integer variables and a return type of void. 4. Look at the following function definition: double getGrossPay(int hoursWorked, double payRate)...

  • C Programming Language 2(a) Define a struct with 1 int array named i, 1 float array...

    C Programming Language 2(a) Define a struct with 1 int array named i, 1 float array named f, and one double array named d, each of size M. (b)Declare array x with N of those structs. (c)Write a void function to traverse array x (using a pointer) assigning to each element in each array d (in each struct in array x) the sum of the corresponding elements in arrays i and f (in the same struct). Use 3 pointers (of...

  • in C++ and also each function has its own main function so please do the main...

    in C++ and also each function has its own main function so please do the main function as well. Previously when i asked the question the person only did the function and didn't do the main function so please help me do it. 1-1. Write a function that returns the sum of all elements in an int array. The parameters of the function are the array and the number of elements in the array. The function should return 0 if...

  • C++ Code Pass By Reference Practice Write the following functions for basic array operations based on...

    C++ Code Pass By Reference Practice Write the following functions for basic array operations based on the function descriptions given below. Write the following functions for basic array operations based on the function descriptions given below. FindMinArray: This function will search an array of integers (passed to the function as a parameter) for its minimum value, then return that value. SumArray: This function will sum an array of integers (passed to the function through a parameter) then return that sum....

  • Using C programming

    Using C, create a data file with the first number being an integer. The value of that integer will be the number of further integers which follow it in the file. Write the code to read the first number into the integer variable how_many.Please help me with the file :((This comes from this question:Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT