Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- public class ComputerSales
- {
- public static void Main(string[] args)
- {
- Console.WriteLine("Enter the number of computer models: ");
- int numModels = int.Parse(Console.ReadLine());
- int totalSales = 0;
- int totalRatings = 0;
- for (int i = 0; i < numModels; i++)
- {
- Console.WriteLine("Enter sales and rating for model {0}: ", i + 1);
- int salesAndRating = int.Parse(Console.ReadLine());
- int sales = salesAndRating / 100; // possible sales
- int rating = salesAndRating % 10; // rating
- totalSales += CalculateSales(sales, rating);
- totalRatings += rating;
- }
- double averageRating = (double)totalRatings / numModels;
- double averageSales = (double)totalSales / numModels;
- Console.WriteLine("Average rating: {0:F2}", averageRating);
- Console.WriteLine("Average sales: {0:F2}", averageSales);
- }
- public static int CalculateSales(int sales, int rating)
- {
- double calculatedSales;
- switch (rating)
- {
- case 2:
- calculatedSales = 0;
- break;
- case 3:
- calculatedSales = sales * 0.5;
- break;
- case 4:
- calculatedSales = sales * 0.7;
- break;
- case 5:
- calculatedSales = sales * 0.85;
- break;
- case 6:
- calculatedSales = sales;
- break;
- default:
- calculatedSales = 0;
- break;
- }
- // Round to second decimal mark using F2 rounding.
- return (int)Math.Round(calculatedSales, 2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement