Question

In: Computer Science

9. Generate a random number between 1 and 8, which is the computer’s number. Ask the...

9. Generate a random number between 1 and 8, which is the computer’s number. Ask the user to guess a number between 1 and 8. Write a sentinel-controlled loop to continue to executed until the user’s guess matches the computer’s number. If the user's guess matches the random number, print a message in green on the SenseHat congratulating the user and then break out of the loop. Otherwise, print a message in red on the SenseHat to ask the user to try again.


10. Write nested for loops that print out the value of each index for each iteration through the loop. The first loop should start at 1 and end at 3 and the second loop should start at 10 and end at 1.

11. Create a grocery store application. Prompt the user to input the number of the number of items, name of the item, and the price each. Use a while with sentinel control to exit the loop when the user enters a number of items less than or equal to 0. At each iteration of the loop, compute the cost of the items as the number of items times the price each. Print out the name of the item and the cost formatted with seven spaces and two decimal places of precision at each iteration. (Hint: Use a priming read for the number of items before you enter the while loop. Within the loop read in the name of the item and the price each and perform the calculation of the cost. Add a loop read that will read in the number of items at the end of the loop code.)

12. Modify the grocery store application in problem 11 to compute the accumulated cost of all items purchased. Prompt the user for the sales tax rate. Compute the sales tax as the sales tax rate times the accumulated cost. Compute the total cost as the accumulated cost plus the sales tax. Print out the total cost formatted with seven spaces and two decimal places of precision.

Solutions

Expert Solution

Did not mation the programing language. so this cause all programs are written in C-language

Program:-

9)

#include <stdio.h>
#include <stdlib.h>
int main() 
{
        int c, n,f=0;
        do
        {
                printf("Guess a Number Between 1 to 8 : ");
                scanf("%d",&c);
        n = rand() % 8 + 1;
        printf("Computer Guess:  %d\n", n);
        printf("Your Guess:  %d\n", c); 
        
        if(c==n)
        {
                printf(" congratulating the user !!\n");
                f=1;
                }
                else
                {
                        printf("Guess did not match , Try again .....\n");
                }

        }while(f!=1);
        return 0;
}

Output

10)

#include<stdio.h>

int main()
{
        int i,j;
        
        for(i=1;i<=3;i++)
        {
                for(j=10;j>=1;j--)
                {
                        printf("index value i :%d\n",i);
                        printf("index value j :%d\n",j);
                }
        }
        return 0;
}

Output

index value i :1
index value j :10
index value i :1
index value j :9
index value i :1
index value j :8
index value i :1
index value j :7
index value i :1
index value j :6
index value i :1
index value j :5
index value i :1
index value j :4
index value i :1
index value j :3
index value i :1
index value j :2
index value i :1
index value j :1
index value i :2
index value j :10
index value i :2
index value j :9
index value i :2
index value j :8
index value i :2
index value j :7
index value i :2
index value j :6
index value i :2
index value j :5
index value i :2
index value j :4
index value i :2
index value j :3
index value i :2
index value j :2
index value i :2
index value j :1
index value i :3
index value j :10
index value i :3
index value j :9
index value i :3
index value j :8
index value i :3
index value j :7
index value i :3
index value j :6
index value i :3
index value j :5
index value i :3
index value j :4
index value i :3
index value j :3
index value i :3
index value j :2
index value i :3
index value j :1

11)

#include <stdio.h>
int main()
{
        int i=1,n;
        float t=0, p[10];
    char name[20];
    printf("\n Enter the number of items: ");
        scanf("%d",& n);
        for(i=0;i<n;i++)
        {
        printf("\nEnter item name: ");
        scanf("%s", name);
        printf("\nEnter Price: ");
        scanf("%f",&p[i]);
        printf("\nYour item is %s.", name);
        printf("\nprice: %.2f",p[i]);
        t=t+p[i];
        }
        printf("\nTotal price: %.2f",t);
        return 0;               
}

Output

12)

#include <stdio.h>
int main()
{
        int i=1,n;
        float t=0, p[10],tax,c;
    char name[20];
    printf("\n Enter the number of items: ");
        scanf("%d",& n);
        printf("\n Enter the Sales Tax: ");
        scanf("%f",&tax);
        
        for(i=0;i<n;i++)
        {
        printf("\nEnter item name: ");
        scanf("%s", name);
        printf("\nEnter Price: ");
        scanf("%f",&p[i]);
        printf("\nYour item is %s.", name);
        printf("\nprice: %.2f",p[i]);
        t=t+p[i];
        }
        printf("\nTotal price: %.2f",t);
        c= t+( t*(tax/100));
        printf("\n Total acumulated Price Adding Tax: %.2f",c);
        return 0;               
}

Output


Related Solutions

A computer random number generator was used to generate 950 random digits from 0 to 9....
A computer random number generator was used to generate 950 random digits from 0 to 9. The observed frequencies of the digits are given in the table below. 0 1 2 3 4 5 6 7 8 9 88 82 97 84 87 87 95 93 90 147 Using a 0.05significance level, test the claim that all of the digits are equally likely. (a) Find the rejection region. Reject H0 if χ2> (b) Find the test statistic. (Round your final...
Create a class called RandomGuess. In this game, generate and store a random number between 1...
Create a class called RandomGuess. In this game, generate and store a random number between 1 and 100. Then, continuously (in a loop): Ask the user to enter a number between 1 and 100 Let the user know if the guess is high or low, until the user enters the correct value If the user enters the correct value, then display a count of the number of attempts it took and exit
A computer random number generator was used to generate 550 random digits (0,1,...,9). The observed frequences...
A computer random number generator was used to generate 550 random digits (0,1,...,9). The observed frequences of the digits are given in the table below. 0 1 2 3 4 5 6 7 8 9 58 55 45 50 53 50 57 57 46 79 Test the claim that all the outcomes are equally likely using the significance level ?=0.05. The expected frequency of each outcome is E= The test statistic is ?2= The p-value is Is there sufficient evidence...
A computer random number generator was used to generate 750 random digits (0,1,...,9). The observed frequences...
A computer random number generator was used to generate 750 random digits (0,1,...,9). The observed frequences of the digits are given in the table below. 0 1 2 3 4 5 6 7 8 9 81 62 74 82 76 75 70 66 80 84 Test the claim that all the outcomes are equally likely using the significance level α=0.05α=0.05. The expected frequency of each outcome is E= The test statistic is χ2= The p-value is Is there sufficient evidence...
JAVA Write a number guessing game that will generate a random number between 1and 20 and...
JAVA Write a number guessing game that will generate a random number between 1and 20 and ask the user to guess that number. The application should start by telling the user what the app does. You should then create the random number and prompt the user to guess it. You need to limit the number of times that the user can guess to 10 times. If the user guesses the number, display some message that tell them that they did...
Collect the Data: Use a random number generator to generate 50 values between 0 and 1...
Collect the Data: Use a random number generator to generate 50 values between 0 and 1 (inclusive). Theoretical Distribution In words, X = The theoretical distribution of X is X ~ U(0, 1). In theory, based upon the distribution X ~ U(0, 1), find μ = __________ σ = __________ 1st quartile = __________ 3rd quartile = __________ median = __________ Construct a box plot of the data. Be sure to use a ruler to scale accurately and draw straight...
Create a class called RandomWhen. The program must continuously generate a random number between 1 and...
Create a class called RandomWhen. The program must continuously generate a random number between 1 and 100 inclusive. The program must stop when the number 1 is generated, and the loop iteration will be printed. Run the program 3 different times. Sample output: It took ## iterations to generate a 1. It took ## iterations to generate a 1. It took # iterations to generate a 1.
In many programming languages you can generate a random number between 1 and a limiting value...
In many programming languages you can generate a random number between 1 and a limiting value named LIMIT by using a statement similar to randomNumber = random(LIMIT). Create the logic for a guessing game in which the application generates a random number and the player tries to guess it. Display a message indicating whether the player’s guess was correct, too high, or too low. (After you finish Chapter 4, you will be able to modify the application so that the...
1. Write a program which simulates rolling dice. It should: Display the random number rolled Ask...
1. Write a program which simulates rolling dice. It should: Display the random number rolled Ask the user if they want to roll again. If they don't want to roll again, the program should end. If they do want to roll again, the new number should display. At a minimum, the die should have 6 sides, but if you want to use a d12 or d20, that is fine too. USE PYTHON
7. Ask the user to type in a number and compare this number with 8. The...
7. Ask the user to type in a number and compare this number with 8. The user could try twice. If the first user input was 8 then print out “Correct!” and terminate the program, otherwise ask user to type in a number for the second time. If the second input was 8 then print out “Correct”, otherwise print “Game over!” Finish the assembly code segment for the above requirement. .data message: .asciiz "Please enter a random number:" right_str: .asciiz...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT