Question

In: Computer Science

Update the function playScratchOffs to do the following Declare an integer variable to store the type...

  1. Update the function playScratchOffs to do the following
    1. Declare an integer variable to store the type of scratch off (i.e. type)
    2. Declare an integer variable to store the number of scratch off (i.e. count)
    3. Declare an integer variable for loop control (i.e. c)
    4. Declare a variable of data type struct OneDollar (i.e. oneSO)
    5. Declare a variable of data type struct TwoDollar (i.e. twoSO)
    6. Declare a variable of data type struct FiveDollar (i.e. fiveSO)
    7. Write a series of printf statements to inform the player the rules of the game; be sure to use format specifiers and constants or variables versus hardcoded values, similar to Figure 1 Scratch Off function output
    8. Write a printf statement to prompt the user for the type of scratch off, similar to Figure 2 User prompts
    9. Save the user input in variable type
    10. Write a printf statement to prompt the user for the number of scratch off, similar to Figure 2 User prompts
    11. Save the user input in variable count
    12. Write a for loop to loop for the number of scratch offs
      1. Write a switch statement evaluating the scratch off type
        1. Case ONE
          1. Set variable struct OneDollar equal to function call createScratchOffOne passing variable struct OneDollar as an argument
          2. Call function displayScratchOffOne passing variable struct OneDollar as an argument
        2. Case TWO
          1. Set variable struct TwoDollar equal to function call createScratchOffTwo passing variable struct TwoDollar as an argument
          2. Call function displayScratchOffTwo passing variable struct TwoDollar as an argument
        3. Case FIVE
          1. Set variable struct FiveDollar equal to function call createScratchOffFive passing variable struct FiveDollar as an argument
          2. Call function displayScratchOffFive passing variable struct FiveDollar as an argument
    13. return the player’s cash balance

----------------------------------------------------------------------------------------------------------------------------------------------

scratchOffs fucntion:

int playScratchOffs(int cash)
{
printf("Let's play scratch off tickets!\n");

return cash;
}

----------------------------------------------------------------------------------------------------------------------------------------------

My Code So Far:

//define struct OneDollar
struct OneDollar {
int winNumber;
int numbers [5];
float prizes [5];
char bonus [2];
int oneSO;
} OneDollar;

//define struc TwoDollar
struct TwoDollar {
int winNumbers [2];
int numbers [10];
float prizes [10];
char bounus [2];
int twoSO;

} TwoDollar;

// define struc FiveDollar

struct FiveDollar {

int winNumbers [4];
int numbers [12];
float prizes [12];
char bonus [4];
int fiveSO;

} FiveDollar;

//function declaration for a. createScratchOffOne

int createScratchOffOne ();

//function declaration for b. displayScratchOffOne

int displayScratchOffOne ();

//function declaration for c. createScratchOffTwo

int createScratchOffTwo ();

//function declaration for d. displayScratchOffTwo

int displayScratchOffTwo ();

//function declaration for e. createScratchOffFive

int createScratchOffFive ();

//function declaration for f. displayScratchOffFive

int displayScratchOffFive ();


int playScratchOffs(int cash)
{
//declare integer variables
int type;
int count;
int c;

//variable declaration with structure

int main () {

struct OneDollar (oneSO);
struct TwoDollar (twoSO);
struct FiveDollar (fiveSO);


}

printf("Let's play scratch off tickets!\n");
printf("Players can select from OneDollar, TwoDollar and FiveDollar tickets\n");
printf("Prizes are based on the ticket selected\n");

clearScreen();

printf ("Which type of scratch off would you like\n");
printf ("(1 = One Dollar, 2 = Two Dollar, 5 = Five Dollar)?\n");
printf ("How many scratch offs would you like?\n");

return cash;
}

Solutions

Expert Solution

Here we just needed to follow line by line instructions provided. Here is the complete code WITH APPROPRIATE COMMENTS EXPLAINING IT.

#include<stdio.h>

int playScratchOffs(int cash){
    // an integer variable to store the type of scratch off (i
    int type;
    int count;
    // loop control
    int c;
    // Declare a variable of data type struct OneDollar (i.e. oneSO)
    struct OneDollar oneSO;
    // Declare a variable of data type struct TwoDollar (i.e. twoSO)
    struct TwoDollar twoSO;
    // Declare a variable of data type struct FiveDollar (i.e. fiveSO)
    struct FiveDollar fiveSO;
    printf("Let's play scratch off tickets!\n");
    // Write a printf statement to prompt the user for the type of scratch off, similar to Figure 2 User prompts
    printf("Enter type of scratch off: ");
    // Save the user input in variable type    // 
    scanf("%d",&type);
    // Write a printf statement to prompt the user for the number of scratch off, similar to Figure 2 User prompts
    printf("Enter for the number of scratch off: ");
    // Save the user input in variable count
    scanf("%d",&count);
    // Write a for loop to loop for the number of scratch offs
    for(c=0;c<count;c++){
        // Write a switch statement evaluating the scratch off type
        switch (type)
        {
            // Case ONE
        case 1:
            oneSO = createScratchOffOne(oneSO);
            displayScratchOffOne(oneSO);
            break;
        // Case TWO
        case 2:
            twoSO = createScratchOffTwo(twoSO);
            displayScratchOffTwo(twoSO);
            break;
        // Case five
        case 5:
            fiveSO = createScratchOffFive(fiveSO);
            displayScratchOffFive(fiveSO);
            break;
        
        }
    }
// RETURN CASH
    return cash;
}

Related Solutions

Questions: 1) // declare integer variable sum equal to zero // declare variable integer i //...
Questions: 1) // declare integer variable sum equal to zero // declare variable integer i // declare while loop condition where i is less then 25 // inside of brackets calculate the sum of i (addition) // increment i // outside the loop print the sum of values ============================================= 2) Create a sentinel value example if I press number 0 it will display the sum of data // create a scanner // prompt the user to to enter the numbers...
1. Declare/define the variable/constant as indicated: a. a variable to store the grade for a student...
1. Declare/define the variable/constant as indicated: a. a variable to store the grade for a student (as whole number) b. a variable to store a letter grade for a course, like A, B, or C c. a variable to store an average for a student (may have decimal places) d. a variable to represent if a student passed the course or not, with a value of TRUE or FALSE e. a constant to represent the passing grade of 65 2....
Assignment 3C: Answer the following questions Question 1. a. Declare a 32-bit signed integer variable and...
Assignment 3C: Answer the following questions Question 1. a. Declare a 32-bit signed integer variable and initialize it with the smallest possible negative decimal value. b. Declare an uninitialized array of 100 16-bit unsigned integers. c. Declare a string variable containing the word “DVC” repeated 20 times, and terminated with the null char. Question 2 For the following declarations, assuming that the address of I is 404000h What are the addresses of J, K, and L? What is the total...
Write a program in c# that declare a variable and store user name jjohn in. Then,...
Write a program in c# that declare a variable and store user name jjohn in. Then, write a statement that will make your program display at the screen the content of that variable, followed by " I would like to know your height in centimeter. Please enter it:". Then, write a statement that will store the value entered by the user, allowing decimal numbers ie some precision, a fraction part. Finally, write statements (more than one can be needed) so...
Part A: Write a set of statements that declare a variable of type double called yourNum,...
Part A: Write a set of statements that declare a variable of type double called yourNum, then prompts the user to input a value which gets stored into that variable. Part B: Write a set of statements that displays the phrase "Even Number!" when the value in the variable count is an even number but displays the phrase “That is odd” otherwise. Declare and initialize all variables. Part C: Write the necessary code to swap (exchange) the values in two...
4. For each of the following haskell type declarations, declare an object of the type this....
4. For each of the following haskell type declarations, declare an object of the type this. a. type this = ([Bool], Float) b. type this = (Float, Integer) -> ([Float], Integer) c. data that = new Char | old Integer type this = [(Float, that)] d. type this = (a, b) -> (a, a)
Which of the following statements is NOT correct? A. It is allowed to declare a variable...
Which of the following statements is NOT correct? A. It is allowed to declare a variable and initialize it in one statement. B. Once a variable is declared and initialized, you can change its value later on. C. The variable declaration tells the compiler to allocate appropriate memory space for the variable based on its data type. D. It is allowed to declare two variables with the same name but with different data type.
C++ Program 1. Declare an integer static array a[ ] with 100 elements. 2. Declare an...
C++ Program 1. Declare an integer static array a[ ] with 100 elements. 2. Declare an integer pointer p. 3. Let p pointing to the array a[ ]. 4. Use p (you have to use p) to put 0 into the first element of this array, 2 into the second element, 4 into the 3rd element, 6 into the 4th element, ... 198 into the 100th element of this array. 5. Use a (you have to use a) to display...
swift language declare a Swift array variable that can hold instances of any class type
swift language declare a Swift array variable that can hold instances of any class type
Java language (a) Write code segments to perform the following: (i) declare and create an integer...
Java language (a) Write code segments to perform the following: (i) declare and create an integer array freqArray of size 8 (ii) declare and initialize an array weight (with suitable type) which contains 48.5, 80 and 68 (iii) declare a Mouse array of size 2 with name mouse and initialize it with Mouse objects using one statement (b) A incomplete definition of a class Temperature is given below: public class Temperature { private double value[] = {36.5, 40, 37, 38.3};...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT