02-2-IF-Calc-Fresh Fruit Stand

Write a program for the FRESH FRUIT STAND business.

Part 1

The fruit stand sells APPLES, GRAPEFRUIT and PEARS only

Each time you start the program you need to get from the owner the selling price of the fruit today.

When a customer asks what is the price for apples the program will display the price for apples only. The same applies to grapefruit and pears.

Apples are sold by the kilo.

Grapefruits are sold by the dozen(12).

Pears are sold by the kilo.

Part 2

Using parts of the program in part 1 modify it so that when a customer comes to pay for their purchase the program will figure out the price.

For simplicity the customer can only buy one product at a time.

Part 3

The fruit stand now sells two types of apples SPARTAN and IDA RED.

Spartan has a slightly higher price than Ida Red apples.

Again the customer can buy only one thing. If they choose apples you need to ask them what type since the price is different.

/* Fruit Calculator Program*/

#include <stdio.h

main()

{ /*Definition of variables*/

doubleo_price = 3.99,

b_price = 0.39,

am_price = 0.89,

ag_price = 0.99,

g_price = 1.00,

total;

charinput;

intquantity;

/*Input from user*/

system("clear");// it calls system and passes a command for it to execute

printf("\n\n\n\t\t\t Welcome to Fresh Fruit Mart\n\n");

printf("We sell:\n\t ORANGES at $3.99/dozen\n");// this would be better if it wasn’t hard coded but …

printf("\t BANANAS at $0.39/pound\n");

printf("\t APPLES at :\n");

printf("\t \tMACINTOSH $0.89/pound\n\t"

"\tGRANNY SMITH at $0.99/pound\n"); // a different way of doing multiple lines

printf("\t GRAPE FRUIT at 3/$1.00\n\n");

printf("\n Enter type of fruit purchased:");

printf("\n\n O - orange");

printf("\n B - banana");

printf("\n M - macintosh apples");

printf("\n S - granny smith apples");

printf("\n G - grapefruit\n");

printf("\n==> ");

scanf("%c",&input);

printf("\n Quantity :");

scanf("%d",&quantity);

printf("\n\n");

/*Calculations and Output */

if (input == 'O')

{ total = (quantity/12) * o_price;

printf("\nYour total is %2.2lf", total);

}

if (input == 'B')

{ total = b_price * quantity;

printf("\nYour total is %2.2lf", total);

}

if (input == 'M')

{ total = am_price * quantity;

printf("\nYour total is %2.2lf", total);

}

if (input == 'S')

{ total = ag_price * quantity;

printf("That's %.2lf please!\n", total);

}

if (input == 'G')

{total = g_price * quantity/3;

printf(" That's %2.2lf please!\n", total);

}

printf("\n\n");

}/* END OF MAIN */

Screen shot of the output

02-2-IF-Calc-Fresh Fruit Stand by rt -- 26 September 20181 of 3