Question

In: Computer Science

Complete function PrintPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than...

Complete function PrintPopcornTime(), with int parameter bagOunces, and void return type. If bagOunces is less than 3, print "Too small". If greater than 10, print "Too large". Otherwise, compute and print 6 * bagOunces followed by " seconds". End with a newline. Example output for ounces = 7:

42 seconds

#include <stdio.h>

void PrintPopcornTime(int bagOunces) {

}

int main(void) {
int userOunces;

scanf("%d", &userOunces);
PrintPopcornTime(userOunces);

return 0;
}

2. Write a function PrintShampooInstructions(), with int parameter numCycles, and void return type. If numCycles is less than 1, print "Too few.". If more than 4, print "Too many.". Else, print "N: Lather and rinse." numCycles times, where N is the cycle number, followed by "Done.". End with a newline. Example output with input 2:

1: Lather and rinse.
2: Lather and rinse.
Done.
 

Hint: Declare and use a loop variable.

#include <stdio.h>

/* Your solution goes here */

int main(void) {
int userCycles;

scanf("%d", &userCycles);
PrintShampooInstructions(userCycles);

return 0;
}

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

1)

#include <stdio.h>

void PrintPopcornTime(int bagOunces) {
if(bagOunces<3)
{
   printf("Too small.\n");
}
else if(bagOunces>10)
{
   printf("Too large.\n");
}
else
{
   printf("%d seconds\n",6*bagOunces);
}
}

int main(void) {
int userOunces;

scanf("%d", &userOunces);
PrintPopcornTime(userOunces);

return 0;
}

___________________________

Output:

_____________________________

2)

#include <stdio.h>

/* Your solution goes here */
void PrintShampooInstructions(int userCycles)
{
   if(userCycles<1)
   {
       printf("\nToo few.\n");
   }
   else if(userCycles>4)
   {
       printf("\nToo many.\n");
   }
   else
   {
       int i;
       for(i=1;i<=userCycles;i++)
       {
           printf("%d: Lather and rinse.\n",i);
       }
       printf("Done\n");
   }
}

int main(void) {
int userCycles;

scanf("%d", &userCycles);
PrintShampooInstructions(userCycles);

return 0;
}

__________________________

Output:

_______________Could you plz rate me well.Thank You


Related Solutions

C++ A void function named NextLeapYear() that takes an int reference parameter. If the parameter is...
C++ A void function named NextLeapYear() that takes an int reference parameter. If the parameter is positive, the function will assign it the next leap year after it; otherwise, the function will assign 4 to it.
Overload and test function getNum(int &) to work with a parameter of type double. 2. Overload...
Overload and test function getNum(int &) to work with a parameter of type double. 2. Overload and test function doubleNum(int) to also work with a parameter of type double. 3. Both functions for collecting input should validate such that negative values would not be allowed. Perform the following steps: a. Add the function prototypes at the top. b. In main(), add a new variable of type double. You can name it "value2" to distinguish from the other variable. c. Write...
What is time Complexity each of the following function? 1- void function(int n) {             for (int...
What is time Complexity each of the following function? 1- void function(int n) {             for (int i=n/2; i<=n; i++)                           for (int j=1; j<=n/2; j++)                                     for (int k=1; k<=n; k = k * 2)                                                 print ”Hello”; } 2- void function(int n) {             for (int i=n/2; i<=n; i++)                           for (int j=1; j<=n; j = 2 * j)                                     for (int k=1; k<=n; k = k * 2)                                                 print ”Hello”; } 3- void function(int n) {             for (int i=1; i<=n; i++)                           for (int j=1;...
(True or False) The following function will compile. void print(int num) { return num+1; } Group...
(True or False) The following function will compile. void print(int num) { return num+1; } Group of answer choices True False Flag this Question Question 2 10 pts (True or False) The following code will output "I was true". bool isGreater(string s1, string s2) { if(s1 > s2) { return true; } return false; } int main() { if(isGreater("before","back")) { cout << "I was true"; } else { cout << "I was false"; } return 0; } Group of answer...
IN C Write a function in the form: void play( int key, int duration) // duration...
IN C Write a function in the form: void play( int key, int duration) // duration units are tenths of a second which generates and prints samples of sin(w*t) for t=0,1,2,...,n-1 which represent a tone corresponding to piano key number key, where: n = (duration/10.0)*8000 w = (2π440rkey-49)/8000 r = 21/12 In the main program call your function to play the first three notes of three blind mice.
Write a C function, for example void sumOfPrime(int n), that takes a positive int n as...
Write a C function, for example void sumOfPrime(int n), that takes a positive int n as a parameter, put all prime numbers less than n into an array, and print out the array and the sum of the numbers in that array. You can use the isPrime function above to save time.
Part 1.1 Write a function whose prototype is void exchange ( /*inout*/ int *p, /*inout*/ int...
Part 1.1 Write a function whose prototype is void exchange ( /*inout*/ int *p, /*inout*/ int *q ) that takes two pointers to integer variables and exchanges the values in these variables. Part 1.2 Write a function whose prototype is char lastChar ( /*in*/ const char *str ) that takes a nonempty C-String as parameter and returns the last character in the string. For example the call lastChar ("srjc") will return the character c. Part 1.3 Define an array of...
Complete the following functions in the Stack.java/Stack.h files (ATTACHED BELOW): a. void push(int val) b. int...
Complete the following functions in the Stack.java/Stack.h files (ATTACHED BELOW): a. void push(int val) b. int pop() c. int getSize() public class Stack {    private int maxStackSize, topOfStack; private int[] stack;    public Stack(int maxStackSize) { if (maxStackSize <= 0) System.out.println("Stack size should be a positive integer."); else { this.maxStackSize = maxStackSize; topOfStack = -1; stack = new int[maxStackSize]; } }    public void push(int val) { // complete this function }    public int pop() { // complete...
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.
/*Use recursion in the function: void getDigit( int num) /* Try this program and implement the...
/*Use recursion in the function: void getDigit( int num) /* Try this program and implement the function void getDigit( intnum) so that it displays the digits in a given number. For example, the number, 1234 consist of 1, 2, 3 and 4. This is an exercise to demonstate the use of a recursive function and the use of recusrion in C++ */ #include #include using namespace std; int main() {      int num;      cout <<"Enter an integer: ";     ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT