Question

The program should prompt the user to enter the numeric code on the fruit's sticker. Codes...

  • The program should prompt the user to enter the numeric code on the fruit's sticker.
  • Codes that are 4 digits long indicate that the fruit has been grown conventionally.
    • In this case, print the message: "Your fruit was grown conventionally, with the use of pesticides and chemicals."
  • Codes that are 5 digits long, and start with an 8, indicate that the fruit has been genetically modified.
    • In this case, print the message: "Your fruit was genetically modified."
  • Codes that are 5 digits long, and start with a 9, indicate that the fruit was grown organically.
    • In this case, print the message: "Your fruit was not genetically modified, and was grown according USDA organic standards."
    • Additionally, your code should use exactly two sets of if-else statements for full credit (note that the use of else if is not allowed on this assignment).
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here I am providing the answer for the above question:

Code:

#include <stdio.h>

int main()
{
int code,data,count=0;
printf("Enter numeric code on the fruit's sticker:");
scanf("%d",&code);
data=code;
while (data != 0)
{
data /= 10;   
++count;
}
if(count==4) //if the code has 4 digits
printf("Your fruit was grown conventionally,with the use of pesticides and chemicals.");
  
if(count==5 && (code>=80000 && code<90000)) //if the code has 5 digits and starting with 8
{
printf("Your fruit was genetically modified.");
}
else
{
if(count==5 && (code>=90000&& code<99999)) //if the code has 5 digits and starting with 9
{
printf("Your fruit was not genetically modified, and was grown accourding USDA organic standards.");
}
}
  

return 0;
}

Screenshot:

Output:

Hoping that the above answer will help you...Thank you...

Add a comment
Know the answer?
Add Answer to:
The program should prompt the user to enter the numeric code on the fruit's sticker. Codes...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Assignment 7.2: Fruit Codes (10 pts) 70% of the produce sold in the U.S. contains pesticide...

    Assignment 7.2: Fruit Codes (10 pts) 70% of the produce sold in the U.S. contains pesticide residues [1]. One large study published in the respected medical journal JAMA, found that people who consumed the most organic foods had 25% fewer cancers than those who ate no organic food [2]. Additionally, foods that are genetically modified tend to be sprayed with large amounts of weed killers [3]. Regardless of these concerns, most nutrition experts agree that eating fruits and vegetables -...

  • Your program must prompt the user to enter a string. The program must then test the...

    Your program must prompt the user to enter a string. The program must then test the string entered by the user to determine whether it is a palindrome. A palindrome is a string that reads the same backwards and forwards, such as "radar", "racecar", and "able was I ere I saw elba". It is customary to ignore spaces, punctuation, and capitalization when looking for palindromes. For example, "A man, a plan, a canal. Panama!" is considered to be a palindrome....

  • For this code after case 0, I need it to ask the user if they would...

    For this code after case 0, I need it to ask the user if they would like to see the menu again and some type of if statement or loop to ask them yes or no and if yes print again and if no end program. So it would ask if they would like to see the menu again then ask what their choice is. If yes print menu and if no end program. import java.util.InputMismatchException; import java.util.*; import java.io.*;...

  • Case questions: What are some major points discussed in the case? Does Monsanto maintain an ethical culture that effec...

    Case questions: What are some major points discussed in the case? Does Monsanto maintain an ethical culture that effectively responds to various stakeholders? How should Monsanto manage the potential harm to plant and animal life from using products such as Roundup? Using the “Four Lenses” to ethical decision making, how do you think Monsanto should handle this ethical dilemma? Monsanto Attempts to Balance Stakeholder Interests Monsanto is a company that has been around since 1901. They have renovated their company...

  • Case questions: What are some major points discussed in the case? Does Monsanto maintain an ethical culture that effec...

    Case questions: What are some major points discussed in the case? Does Monsanto maintain an ethical culture that effectively responds to various stakeholders? How should Monsanto manage the potential harm to plant and animal life from using products such as Roundup? Using the “Four Lenses” to ethical decision making, how do you think Monsanto should handle this ethical dilemma? Monsanto Attempts to Balance Stakeholder Interests Monsanto is a company that has been around since 1901. They have renovated their company...

  • This is for a Unix class. Please help me out. I am attaching a skeletal code of the program below, it just needs ti be filled in. Below is a skeletal code of the program. Fork a child process...

    This is for a Unix class. Please help me out. I am attaching a skeletal code of the program below, it just needs ti be filled in. Below is a skeletal code of the program. Fork a child process and then use the parent for reading and the child for writing.  This is just a way of sending and receiving messages asynchronously. /* ************************************************************* * Utility functions * ************************************************************** */ static void usageError(const char * progName, const char *msg) {...

  • For this assignment, you will write a program to work with Huffman encoding. Huffman code is...

    For this assignment, you will write a program to work with Huffman encoding. Huffman code is an optimal prefix code, which means no code is the prefix of another code. Most of the code is included. You will need to extend the code to complete three additional methods. In particular, code to actually build the Huffman tree is provided. It uses a data file containing the frequency of occurrence of characters. You will write the following three methods in the...

  • In the program, the zipcode will be represented by an integer and the corresponding barcode will...

    In the program, the zipcode will be represented by an integer and the corresponding barcode will be represented by a string of digits. The digit 1 will represent the long bar, and the digit 0 will represent the short bar, The first and last digits of a POSTNET code are always 1. Stripping these leaves 25 digits, which can be split into groups of 5. The above example translates into the following string and groups of five: 101100100010010101100110001 01100 10001...

  • I keep getting an error code in my C++ program. It says "[Error] 'strlen' was not...

    I keep getting an error code in my C++ program. It says "[Error] 'strlen' was not declared in this scope" in my main.cpp. Here are my codes. main.cpp #include <iostream> #include <string> #include "functions.h" using namespace std; //definition of the main function. //takes arguments from the command-line. int main(int argc, char *argv[]) { //Determine if you have enough arguments. //If not, output a usage message and exit program if (argc<2 || (argc == 2 && argv[1][0] == '-')) { //call...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT