1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
pav-90 [236]
3 years ago
10

In C Coding, print either "Fruit", "Drink", or "Unknown" (followed by a newline) depending on the value of userItem. Print "Unkn

own" (followed by a newline) if the value of userItem does not match any of the defined options. For example, if userItem is GR_APPLES, output should be:
Fruit
Sorry in advance, I'm new and my professor has been a bit hard to understand so I'd like a walkthrough on this problem.
Computers and Technology
1 answer:
shutvik [7]3 years ago
6 0

The code below uses if-else structure to print the output depending on the value of the userItem.

If the specified condition in the if structure is true, the block in the structure gets executed.

Comments are used to explain the each line of the code.

//main.c

#include <stdio.h>

int main()

{  

   //defining the enum and userItem

   enum GroceryItem {GR_APPLES, GR_BANANAS, GR_JUICE, GR_WATER};

   enum GroceryItem userItem;

   //initializing the userItem

   userItem = GR_APPLES;

   

   //checking the userItem

   //If it is GR_APPLES or GR_BANANAS, print "Fruit"

   //If it is GR_JUICE or GR_WATER, print "Drink"

   //Otherwise, print "Unknown"

   if(userItem == GR_APPLES || userItem == GR_BANANAS){

       printf("%s\n", "Fruit");

   }

   else if(userItem == GR_JUICE || userItem == GR_WATER){

       printf("%s\n", "Drink");

   }

   else{

       printf("%s\n", "Unknown");

   }

   

   return 0;

}

You can see a similar question at:

brainly.com/question/17592042

You might be interested in
Which of the following is the term for a device (usually external to a computer) that is plugged into a computer's communication
Serjik [45]

A device, usually external to a computer that is plugged into a computer's communication port or is connected wirelessly. Common peripherals are keyboards, mice, monitors, speakers, and printers

4 0
3 years ago
Choose the appropriate software category for each specific application shown.
Tom [10]
Python is the correct answer
7 0
2 years ago
The faster alcohol is consumed, the faster it reaches the __________.
Anni [7]
The faster it reaches the bloodstream

6 0
3 years ago
Read 2 more answers
1. Assume that word is a variable of type String that has been assigned a value . Assume furthermore that this value always cont
s2008m [1.1K]

Answer:

1.word = "George slew the dragon"

startIndex = word.find('dr')

endIndex = startIndex + 4

drWord = word[startIndex:endIndex]

2. sentence = "Broccoli is delicious."

sentence_list = sentence.split(" ")

firstWord = sentence_list[0]

Explanation:

The above snippet is written in Python 3.

1. word is initialized to a sentence.

Then we find the the occurence of 'dr' in the sentence which is assign to startIndex

We then add 4 to the startIndex and assign it to endIndex. 4 is added because we need a length of 4

We then use string slicing method to create a substring from the startIndex to endIndex which is assigned to drWord.

2. A string is assigned to sentence. Then we split the sentence using sentence.split(" "). We split based on the spacing. The inbuilt function of split returns a list. The first element in the list is assigned to firstWord. List uses zero based index counting. So. firstWord = sentence_list[0] is use to get first element.

4 0
4 years ago
Write a piece of code that constructs a jagged two-dimensional array of integers named jagged with five rows and an increasing n
Ksivusya [100]

Answer:

Explanation:

The following code is written in Java and it uses nested for loops to create the array elements and then the same for loops in order to print out the elements in a pyramid-like format as shown in the question. The output of the code can be seen in the attached image below.

class Brainly {

   public static void main(String[] args) {

       int jagged[][] = new int[5][];

       int element = 1;

       for(int i=0; i<5; i++){

           jagged[i] = new int[i+1]; // creating number of columns based on current value

           for(int x = 0; x < jagged[i].length; x++) {

               jagged[i][x] = element;

               element += 1;

           }

       }

       System.out.println("Jagged Array elements are: ");

       for ( int[] x : jagged) {

           for (int y : x) {

               System.out.print(y + " ");

           }

           System.out.println(' ');

       }

       }

   }

4 0
3 years ago
Other questions:
  • Write a program to read as many test scores as the user wants from the keyboard (assuming at most 50 scores). Print the scores i
    13·1 answer
  • 3.What is deep focus, and when is it a good choice for a scene?
    8·1 answer
  • NEED HELP PLEASEE!!!
    9·1 answer
  • Write a program in Python that reads in investment amount, annual interest rate, and number of years, and displays the future in
    6·1 answer
  • Your team has been asked to design a LAN for a very successful CPA firm with five departments in one building and a total of 560
    6·1 answer
  • Chapter 15 Problem 6 PREVENTIVE CONTROLS Listed here are five scenarios. For each scenario, discuss the possible damages that ca
    11·1 answer
  • Pls explain the meaning of the word"INTERNET"​
    5·2 answers
  • Is there a way of how to delete this if so pleas tell me
    11·1 answer
  • What is a cookie? *
    9·2 answers
  • A small square at the right corner of the table is what?​
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!