SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Barbara Dolye
Chapter:
Data Types And Expressions
Exercise:
Programming Exercises
Question:9 | ISBN:9781285096261 | Edition: 4

Question

Write a program that computes the amount of money the computer club will receive from the proceeds of their granola project. Each case has 100 bars. The ranola bars sell for $1.50 per bar. Each case costs $100.00. They are required to give the student government association 10% of their earnings. Display their proceeds, showing the amount given to the student government association. Show all the values formatted with currency. Do a compile-time initialization using 29 for cases sold.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

using System;

class Program
{
    static void Main()
    {
        const int casesSold = 29;    // Number of cases sold
        const double barPrice = 1.50;    // Price of each granola bar
        const double caseCost = 100.00;    // Cost of each case
        const double sgaPercentage = 0.10;    // Percentage of earnings to give to student government association

        // Calculate the total earnings
        double totalEarnings = casesSold * caseCost * barPrice;

        // Calculate the amount to give to the student government association
        double sgaAmount = totalEarnings * sgaPercentage;

        // Calculate the proceeds after giving to SGA
        double proceeds = totalEarnings - sgaAmount;

        // Display the results
        Console.WriteLine("Granola Project Proceeds");
        Console.WriteLine("-----------------------");
        Console.WriteLine("Cases Sold: {0}", casesSold);
        Console.WriteLine("Earnings: {0:C}", totalEarnings);    // Display earnings as currency
        Console.WriteLine("SGA Amount: {0:C}", sgaAmount);    // Display SGA amount as currency
        Console.WriteLine("Proceeds: {0:C}", proceeds);    // Display proceeds as currency
    }
}

Executed Output:

Granola Project Proceeds
-----------------------
Cases Sold: 29
Earnings: $4,350.00
SGA Amount: $435.00
Proceeds: $3,915.00

 

0 0

Discussions

Post the discussion to improve the above solution.