Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

Answer the following question and submit in the textbox provided.

A fruit store sells the following in parcels at the given price:

apple $100
grape $250
banana $75
naseberry $125
pine $300

Write an algorithm that will enable the user to purchase 3 different types of fruit. It is
important to state the number of parcels of each fruit that is being purchased.

The program should then display the total cost for each fruit purchased as well as the total
cost of the order. You are responsible for determining how best to display your output.

Write a pseudocode to solve the problem above. (10 marks)


Start
string fruit1
string fruit2
string fruit3
decimal fruit1cost
decimal fruit2cost
decimal fruit3cost
decimal quantity1
decimal quantity2
decimal quantity3

WriteLine("Enter the first fruit")


fruit1= ReadLine()
WriteLine("Enter the quantity of first fruit")
quantity1= ReadLine()

WriteLine("Enter second fruit")


fruit2= ReadLine()

WriteLine("Enter the quantity of second fruit")


quantity2= ReadLine()

WriteLine("Enter the third fruit")


fruit3= ReadLine()

WriteLine("Enter the quantity of third fruit")


quantity3= ReadLine()

fruit1cost=0

if(fruit1="apple")
fruit1cost=100*quantity1

else if(fruit1="grape")
fruit1cost=250*quantity1

else if(fruit1="banana")
fruit1cost=75*quantity1

else if(fruit1="naseberry")
fruit1cost=125*quantity1
else if(fruit1="pine")
fruit1cost=300*quantity1

else if(fruit1!="apple" and fruit1!="grape" and fruit1!="banana" and fruit1!="naseberry" and


fruit1!="pine")
WriteLine("The wrong fruit was entered for first fruit")

fruit2cost=0

if(fruit2="apple")
fruit2cost=100*quantity2

else if(fruit2="grape")
fruit2cost=250*quantity2

else if(fruit2="banana")
fruit2cost=75*quantity2

else if(fruit2="naseberry")
fruit2cost=125*quantity2

else if(fruit2="pine")
fruit2cost=300*quantity2

else if(fruit2!="apple" and fruit2!="grape" and fruit2!="banana" and fruit2!="naseberry" and


fruit2!="pine")
WriteLine("The wrong fruit was entered was entered for second fruit")

fruit3cost=0
if(fruit3="apple")
fruit3cost=100*quantity3

else if(fruit3="grape")
fruit3cost=250*quantity3

else if(fruit3="banana")
fruit3cost=75*quantity3

else if(fruit3="naseberry")
fruit3cost=125*quantity3

else if(fruit3="pine")
fruit3cost=300*quantity3

else if(fruit3!="apple" and fruit3!="grape" and fruit3!="banana" and fruit3!="naseberry" and


fruit3!="pine")
WriteLine("The wrong fruit was entered for third fruit")

if(fruit1cost>0 and fruit2cost>0 and fruit3cost>0)


{
WriteLine("The cost for the first item is ${0:N2}",fruit1cost)
WriteLine("The cost for the second item is ${0:N2}",fruit2cost)
WriteLine("The cost for the third item is ${0:N2}",fruit3cost)
WriteLine("The total cost is ${0:N2}",fruit1cost+fruit2cost+fruit3cost)
}

else
WriteLine("Incorrect input was made")
Stop
Convert your algorithm/pseudocode to C# (15 marks)
using System;

public class Program


{
public static void Main()
{
string fruit1;
string fruit2;
string fruit3;
float fruit1cost;
float fruit2cost;
float fruit3cost;
float quantity1;
float quantity2;
float quantity3;

Console.WriteLine("Enter the first fruit");


fruit1=Console.ReadLine();

Console.WriteLine("Enter the quantity of first fruit");


quantity1=Convert.ToSingle(Console.ReadLine());

Console.WriteLine("Enter second fruit");


fruit2=Console.ReadLine();

Console.WriteLine("Enter the quantity of second fruit");


quantity2=Convert.ToSingle(Console.ReadLine());

Console.WriteLine("Enter the third fruit");


fruit3=Console.ReadLine();

Console.WriteLine("Enter the quantity of third fruit");


quantity3=Convert.ToSingle(Console.ReadLine());

fruit1cost=0;

if(fruit1=="apple")
fruit1cost=100*quantity1;

else if(fruit1=="grape")
fruit1cost=250*quantity1;

else if(fruit1=="banana")
fruit1cost=75*quantity1;

else if(fruit1=="naseberry")
fruit1cost=125*quantity1;

else if(fruit1=="pine")
fruit1cost=300*quantity1;

else if(fruit1!="apple" && fruit1!="grape" && fruit1!="banana" && fruit1!


="naseberry" && fruit1!="pine")
Console.WriteLine("The wrong fruit was entered for first fruit");

fruit2cost=0;

if(fruit2=="apple")
fruit2cost=100*quantity2;
else if(fruit2=="grape")
fruit2cost=250*quantity2;

else if(fruit2=="banana")
fruit2cost=75*quantity2;

else if(fruit2=="naseberry")
fruit2cost=125*quantity2;

else if(fruit2=="pine")
fruit2cost=300*quantity2;

else if(fruit2!="apple" && fruit2!="grape" && fruit2!="banana" && fruit2!


="naseberry" && fruit2!="pine")
Console.WriteLine("The wrong fruit was entered for second fruit");

fruit3cost=0;

if(fruit3=="apple")
fruit3cost=100*quantity3;

else if(fruit3=="grape")
fruit3cost=250*quantity3;

else if(fruit3=="banana")
fruit3cost=75*quantity3;

else if(fruit3=="naseberry")
fruit3cost=125*quantity3;
else if(fruit3=="pine")
fruit3cost=300*quantity3;

else if(fruit3!="apple" && fruit3!="grape" && fruit3!="banana" && fruit3!


="naseberry" && fruit3!="pine")
Console.WriteLine("The wrong fruit was entered for third fruit");

if(fruit1cost>0 && fruit2cost>0 && fruit3cost>0)


{
Console.WriteLine("The cost for the first item is ${0:N2}",fruit1cost);
Console.WriteLine("The cost for the second item is
${0:N2}",fruit2cost);
Console.WriteLine("The cost for the third item is ${0:N2}",fruit3cost);
Console.WriteLine("The total cost is
${0:N2}",fruit1cost+fruit2cost+fruit3cost);
}

else
Console.WriteLine("Incorrect input was made");

}
}

You might also like