Advertisement
Ang377ou

items

Mar 23rd, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace activity6
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. string[] items = { "Notebook", "Ballpen", "Crayon","Eraser" };
  13. int[] weigth = { 60, 40, 25,15 };
  14. int[] value = { 20, 15, 10,5 };
  15. int[] i = { 3, 4, 5,6 };
  16.  
  17. int WEIGTH, sum = 0;
  18. string ITEMS = "";
  19. int index = 0, totalweigth = 0, totalvalue = 0;
  20.  
  21. Console.Write("Enter weight:");
  22. WEIGTH = int.Parse(Console.ReadLine());
  23.  
  24. while (sum <= WEIGTH && index < weigth.Length)
  25. {
  26. if (sum + weigth[index] <= WEIGTH)
  27. {
  28. totalweigth = totalweigth + weigth[index];
  29. totalvalue = totalvalue + value[index];
  30. sum = sum + weigth[index];
  31. ITEMS = ITEMS +"\t"+ items[index] +"\t"+ weigth[index]+"grams" +"\t"+ value[index]+"pesos";
  32. i[index] = i[index] - 1;
  33. Console.WriteLine("\nItems:" + ITEMS);
  34. }
  35. if (i[index] == 0 || weigth[index] > (WEIGTH - sum))
  36. {
  37. index++;
  38.  
  39. }
  40.  
  41. }
  42. Console.WriteLine( "\ntotal weigth:" + totalweigth+"grams" + "\ntotal value:" + totalvalue+"pesos");
  43.  
  44.  
  45.  
  46. Console.ReadKey();
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement