Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Understanding the decisions structure only requires you examining the wording an

ID: 664424 • Letter: U

Question

Understanding the decisions structure only requires you examining the wording and converting it to an IF...THEN...ELSE statement. FYI - I have posted notes under the CONTENT section explaining the IF...THEN...ELSE statement. I would strongly encourage that you read it before completing this posting.

Instructions: I would like you to take the following paragraphs and convert them to IF...THEN...ELSE statements.

Print a list of best-selling items. Best-selling items are those that sell more than 2000 pounds per month.

I am doing the first one for you. Let’s examine the word problem.

What's my output?

Print a list of best-selling items.

How do you know what is considered a best-selling item?

Best-selling items are those that sell more than 2000 pounds per month.

How do I form this into a question using only the Boolean operators (<, <=, >, >=, =, and <> found on page 126)?

Best-selling items are those that sell more than 2000 pounds per month.

BestSellingItems > 2000

Do I have a false path (ELSE)? If the items are less than 2000 pounds, do I do anything? No. I only want to display the items that are more than 2000 pounds per month. NOTE: You only use the ELSE path if you need to execute a false path.

So here is the pseudocode:

start

Input BestSellingItems

if BestSellingItems > 2000 then

Output BestSellingItems

endif

Now complete the following:

A program that accepts data about a phone call and displays all the details about a call that costs over $10.

Display a student’s data if the student’s grade point average is below 2.0.

Explanation / Answer

The if-then-Else Statement

The if-then statement is the most basic of all the control flow statements. It tells your program to execute a certain section of code only if a particular test evaluates to true.The if-then-else statement provides a secondary path of execution when an "if" clause evaluates to false.

Example

Grade based on the value of a test score: an A for a score of 90% or above, a B for a score of 80% or above, and so on.

The output from the program is:

Here you can see that the value of testscore can satisfy more than one expression in the compound statement: 76 >= 70 and 76 >= 60. However, once a condition is satisfied, the appropriate statements are executed (grade = 'C';) and the remaining conditions are not evaluated.

Print a list of best-selling items.

#include <stdio.h>
int main(void){
int BestSellingItems;
printf("Enter your total sell items ");
scanf("%d",&BestSellingItems );
printf(" You entered %d", BestSellingItems ); // printing outputs

if(BestSellingItems >= 2000)

{
printf(" BestSellingItems "); // printing outputs
}
else

if ( BestSellingItems < 2000)

{
printf(" Item is not BestSellingItems ");
}
return 0;
}

A program that accepts data about a phone call and displays all the details about a call that costs over $10.

start

num custAreaCode

num custPhoneNum

num calledAreaCode

num calledPhoneNum

num minutes

num price

num LOW_RATE = 0.10

num HIGH_RATE = 0.13

num TIME_LIMIT = 20

      get custAreaCode, custPhoneNum, calledAreaCode, calledPhoneNum, minutes

      if custAreaCode not equal to calledAreaCode AND

            minutes > TIME_LIMIT then

            price = minutes * LOW_RATE

      else

            price = minutes * HIGH_RATE

   endif

   if price > 10 then

         print custAreaCode, custPhoneNum, calledAreaCode, calledPhoneNum, price

   endif

stop

Display a student’s data if the student’s grade point average is below 2.0.

start

      num id

num Stu_gpa

string firstName

string lastName

string major

num stu_Stu_gpa = 2.0

      getid, firstName, lastName, major, Stu_gpa

      if Stu_gpa < Stu_gpa then

            printid, firstName, lastName, major, Stu_gpa

      endif    

stop