Advertisement
CR7CR7

salesTask

Oct 15th, 2023
745
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.66 KB | None | 0 0
  1. using System;
  2.  
  3. public class ComputerSales
  4. {
  5.     public static void Main(string[] args)
  6.     {
  7.         Console.WriteLine("Enter the number of computer models: ");
  8.         int numModels = int.Parse(Console.ReadLine());
  9.  
  10.         int totalSales = 0;
  11.         int totalRatings = 0;
  12.  
  13.         for (int i = 0; i < numModels; i++)
  14.         {
  15.             Console.WriteLine("Enter sales and rating for model {0}: ", i + 1);
  16.             int salesAndRating = int.Parse(Console.ReadLine());
  17.  
  18.             int sales = salesAndRating / 100; // possible sales
  19.             int rating = salesAndRating % 10; // rating
  20.  
  21.             int calculatedSales;
  22.             switch (rating)
  23.             {
  24.                 case 2:
  25.                     calculatedSales = 0;
  26.                     break;
  27.                 case 3:
  28.                     calculatedSales = (int)(sales * 0.5);
  29.                     break;
  30.                 case 4:
  31.                     calculatedSales = (int)(sales * 0.7);
  32.                     break;
  33.                 case 5:
  34.                     calculatedSales = (int)(sales * 0.85);
  35.                     break;
  36.                 case 6:
  37.                     calculatedSales = sales;
  38.                     break;
  39.                 default:
  40.                     calculatedSales = 0;
  41.                     break;
  42.             }
  43.  
  44.             totalSales += calculatedSales;
  45.             totalRatings += rating;
  46.         }
  47.  
  48.         double averageRating = (double)totalRatings / numModels;
  49.         double averageSales = (double)totalSales / numModels;
  50.  
  51.         Console.WriteLine("Average rating: {0}", averageRating);
  52.         Console.WriteLine("Average sales: {0}", averageSales);
  53.     }
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement