Question

In: Computer Science

Must be written in C: Lab 3: Logical Expressions and if Statements Project Goals The goals...

Must be written in C:

Lab 3: Logical Expressions and if Statements

Project Goals

The goals of this project are to:

1. Get students familiar with evaluating logical expressions

2. Get students familiar with

if - else

statements

Important Notes:

1.

Formatting:

Make sure that you follow the precise recommendations for the

output content and formatting: for example, do not change the text of the problem from

Enter the number of loaves of bread and price per loaf:

” to

Enter

bread and price:

. Your assignment will be auto-graded and any change in

formatting will result in a loss in the grade.

2.

Comments:

Header comments are required on all files and recommended for the

rest of the program. Points will be deducted if no header comments are included.

Problem 1

Save your program as

party.c

Perry is throwing a tea party and needs to buy supplies. Write a program that asks the user to

enter information about bread and butter. Each item has a number of units and a price per unit.

The program will ask how many of each item Perry wants and the price per item. Then the

program will ask for Perry’s budget. All values entered will be integers. The program will then

evaluate a set of logical expressions and print out specific messages based on the truth value of

those expressions. The expressions are as follows:

(1)

Perry has money

.

If the condition is true the program will print:

(1) Perry has some money to buy party supplies.

If the condition is false, the program should print:

(1) Perry does not have money to buy anything.

(2)

Perry can get at least one of his supplies.

If Perry can buy at least one of the supplies, the program should print:

(2) Perry can buy at least one of the supplies.

If Perry can’t buy any supplies, the program should print:

(2) Perry is going to have a very sad party.

(3)

Perry can buy all of his supplies

.

If the condition is true, the program should print:

(3) Perry can buy all of the supplies.

If the condition is false, the program should print:

(3) Perry can’t buy all of his supplies.

The program should function as follows (items underlined are to be entered by the user):

Enter the number of sticks of butter and price per stick: 2 20

Enter the number of loaves of bread and price per loaf: 3 30

Enter Perry's budget: 100

(1) Perry has some money to buy party supplies.

(2) Perry can buy at least one of the supplies.

(3) Perry can’t buy all of his supplies.

Run your program again, testing it with different values.

Notes:

Your program should print out in the same order as the project description.

Your program should only ever print out one statement for every condition

Solutions

Expert Solution

//main program
#include<stdio.h>
int main()
{
printf("Enter the number of sticks of butter and price per stick: ");
int butter,butter_price; //to store butter and it's price;
scanf("%d%d",&butter,&butter_price);
printf("Enter the number of loaves of bread and price per loaf: ");
int loaf,loaf_price; //to store loaf and it's price
scanf("%d%d",&loaf,&loaf_price);
printf("Enter Perry's budget: ");
int budget; //to store budget
scanf("%d",&budget);
if(budget>=butter_price || budget>=loaf_price) //if budget is greater than any of the price, he can atleast buy single stuff
printf("(1) Perry has some money to buy party supplies.\n");
else
{
printf("(1) Perry does not have money to buy anything.\n");
return 0;
}
if(budget>=(butter_price*butter) || budget>=(loaf_price*loaf)) //if he can buy atleat one stuff completly
printf("(2) Perry can buy at least one of the supplies.\n");
else
{
printf("(2) Perry is going to have a very sad party.\n");
return 0;
}
if(budget>=(butter_price*butter)+(loaf_price*loaf)) //if budget is greter than total cost of supplies
printf("(3) Perry can buy all of the supplies.\n");
else
{
printf("(3) Perry can’t buy all of his supplies.\n");
return 0;
}
return 0;
}


Related Solutions

Must be written in C++ in Visual studios community In this lab, you will modify the...
Must be written in C++ in Visual studios community In this lab, you will modify the Student class you created in a previous lab. You will modify one new data member which will be a static integer data member. Call that data member count. You also add a static method to the Student class that will display the value of count with a message indicating what the value represents, meaning I do not want to just see a value printed...
Project [2]: Expressions and Operators Project Goals The goal of this project is to: 1. Get...
Project [2]: Expressions and Operators Project Goals The goal of this project is to: 1. Get students familiar with expressions and operators. Important Notes: 1. Formatting: Make sure that you follow the precise recommendations for the output content and formatting. For example, do not change the text from “You’re walking through the woods and come upon a chest. Do you open it? 1 – yes 2 - no” to “Do you open the chest? ”. Your assignment will be auto-graded...
Lab Project 3: Lab Safety
Lab Project 3: Lab Safety 1. List the items of proper lab dress. 2. Describe a how you would use your cell phone in the microbiology lab. 3. List the safety equipment found in labs. 4. Identify the reason you would not use carbon dioxide extinguisher on a person 5. List personal habits that should be avoided in the lab.
Answers must be complete, logical, thoughtful, supported by examples, and well written. Identify the four major...
Answers must be complete, logical, thoughtful, supported by examples, and well written. Identify the four major categories of legal entities available to new businesses. Give an example of each. For each of the following, identify a business that would be appropriate for the form of organization specified. List the reasons why this form of organization would be appropriate for the business that you have identified. Sole proprietorship General partnership Limited partnership Corporation S-Corporation LLC What is bankruptcy? Is there more...
Must be written in Java: After completing this lab, you should be able to: Write a...
Must be written in Java: After completing this lab, you should be able to: Write a Java class to represent Time. Create default and parameterized constructors. Create accessor and mutator methods. Write a toString method. This project will represent time in hours, minutes, and seconds. Part 1: Create a new Java class named Time that has the following instance fields in the parameterized constructor: hours minutes seconds Create a default constructor that sets the time to that would represent the...
The following question must be answered in the C programming language and may not be written...
The following question must be answered in the C programming language and may not be written in C++ or any other variation. Problem 5 This problem is designed to make sure you can write a program that swaps data passed into it such that the caller's data has been swapped. This is something that is done very frequently in manipulating Data Structures. The Solution / Test Requirements I want your program to demonstrate that you understand how to swap information...
Discret Math MATH/CSCI2112 (3) (a) Write the following premises and the conclusion as logical statements and...
Discret Math MATH/CSCI2112 (3) (a) Write the following premises and the conclusion as logical statements and prove the conclusion correct: (use the symbols in brackets). If the flight is late, I will spend the night in Toronto. If I miss my flight I will spend the night in Winnipeg. Either my flight is not late, or I did not miss my flight from Winnipeg, but not both. Therefore either I will spend the night in Toronto, or I will spend...
C++ Write a program that outputs an amortization schedule for a given loan. Must be written...
C++ Write a program that outputs an amortization schedule for a given loan. Must be written using user-defined functions must take at least 1 argument Output number of months, payment, interest to pay, principle to pay, and ending balance
Hypotheses can be written as questions, statements and equality/inequalities. To be truly proficient, you must be...
Hypotheses can be written as questions, statements and equality/inequalities. To be truly proficient, you must be able to interpret a hypothesis, regardless of how it is expressed. Hypothesis: Explain in words. Directional or Non-directional? Null or Alternative? Example: μ0 = μ1 μ0 < μ1 μ0 > μ1
Must be written in JAVA Code Modify the program you created in previous project to accomplish...
Must be written in JAVA Code Modify the program you created in previous project to accomplish the following: Support the storing of additional user information: street address (string), city( string), state (string), and 10-digit phone number (long integer, contains area code and does not include special characters such as '(', ')', or '-' Store the data in an ArrayList object Program to Modify import java.util.ArrayList; import java.util.Scanner; public class Address { String firstname; String lastname; int zipcode;    Address(String firstname,String...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT