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....
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...
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.
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
Output with Vars.java A variable like userNum can store a value like an integer. Extend the...
Output with Vars.java A variable like userNum can store a value like an integer. Extend the given program as indicated. Output the user's input. (2 pts) Output the input squared and cubed. Hint: Compute squared as userNum * userNum. (2 pts) Get a second user input into userNum2, and output the sum and product. (1 pt) Note: This zyLab outputs a newline after each user-input prompt. For convenience in the examples below, the user's input value is shown on the...
In C++, type a function function(int n, int base) that converts a positive integer x to...
In C++, type a function function(int n, int base) that converts a positive integer x to any base between 2 and 9. The function HAS to do this using a stack, and using methods from below: +isEmpty(): boolean +push(newEntry: ItemType): boolean +pop(): boolean +peek(): ItemType (Also, type a program to test the function). Hint: could use simple iteration continually divides the decimal number by base and keeps track of the remainder by using a stack.
Declare and initialize an array to store the course name or code.
Declare and initialize an array to store the course name or code.
Write a C program to Declare an integer array of size 10 with values initialized as...
Write a C program to Declare an integer array of size 10 with values initialized as follows. int intArray[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; Compute each item of a new array of same size derived from the above array by: adding first item (intArray[0]) of the array with 3rd, 2nd with 4th, 3rd with 5th and so on. For the last-but-one item intArray[8], add it with first item and for the last item (intArray[9])...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT