c# - Array value in a set of value ranges isn't displaying -
i'm trying make simple program display discount depending on how many items customer purchases.
using system; using system.collections.generic; using system.linq; using system.text; namespace consoleapplication11 { class program { const int size = 4; static void main(string[] args) { int itemsbought = 0; double discountitem = 0; int[] items = new int[size] { 0, 10, 26, 61 }; double[] discount = new double[size] { 0.0, 0.05, 0.10, 0.15 }; inputitems(ref itemsbought); getdiscount(items, discount, ref itemsbought, ref discountitem); console.writeline("your discount {0}", discountitem); } private static void getdiscount(int[] items, double[] discount, ref int itemsbought, ref double discountitem) { int idx = 0; (idx = 1; idx >= items.length; idx++) { while (itemsbought >= items[idx]) { discountitem = discount[idx]; idx++; } } } private static void inputitems(ref int itemsbought) { console.writeline("enter amount of items bought"); while (!int.tryparse(console.readline(), out itemsbought)) console.writeline("error, whole numbers only"); } } }
somehow know logic of bad not sure. topic 1 being of course discount aligns input displaying. it's displaying "the discount 0" no matter value inputed.
your for
loop wrong. first, isn't executing because condition idx >= items.length;
. should opposite: idx < items.length;
. second, i'm not sure why setting idx
1
in initializer...
the inner while loop doesn't want to, i'm not sure want in first place.
Comments
Post a Comment