Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace activity6
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] items = { "Notebook", "Ballpen", "Crayon","Eraser" };
- int[] weigth = { 60, 40, 25,15 };
- int[] value = { 20, 15, 10,5 };
- int[] i = { 3, 4, 5,6 };
- int WEIGTH, sum = 0;
- string ITEMS = "";
- int index = 0, totalweigth = 0, totalvalue = 0;
- Console.Write("Enter weight:");
- WEIGTH = int.Parse(Console.ReadLine());
- while (sum <= WEIGTH && index < weigth.Length)
- {
- if (sum + weigth[index] <= WEIGTH)
- {
- totalweigth = totalweigth + weigth[index];
- totalvalue = totalvalue + value[index];
- sum = sum + weigth[index];
- ITEMS = ITEMS +"\t"+ items[index] +"\t"+ weigth[index]+"grams" +"\t"+ value[index]+"pesos";
- i[index] = i[index] - 1;
- Console.WriteLine("\nItems:" + ITEMS);
- }
- if (i[index] == 0 || weigth[index] > (WEIGTH - sum))
- {
- index++;
- }
- }
- Console.WriteLine( "\ntotal weigth:" + totalweigth+"grams" + "\ntotal value:" + totalvalue+"pesos");
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement