c# - Keeps crashing on 3rd if condition -


so kind of new programming (16 y/o) , have been solving problems while now, solving 1 prob (which quite easy) there seems 1 thing getting on way. problem pretty simple, needs me read 3 integers , print out greatest one, have solved in c++/c , had no problem, @ all. one, prints out , works when first 2 if conditions true (if greatest value, prints a, if b greatest value prints b) when c greatest value comes out empty. sorry long post, hope can me out.

 using system;

namespace maxp351 { class mainclass { public static void main (string[] args) { string[] input = console.readline ().split (' '); // getting input string int[] nums = new int[input.length]; // declaring int array same length input (int = 0; < input.length; i++) { // starting loop convert input string int in nums[] nums[i] = convert.toint32(input[i]); } int a, b, c; = nums [0]; b = nums [1]; c = nums [2]; if (a > b && > c) { console.writeline (a); break; } else if (b > && b > c) { console.writeline (b); break; } else if (c > && c > b) { console.writeline (c); break; }

} }

if c largest number code should printing out value c. if code, set break point @ if statement , see values are. alternatively can print out values of a,b , c right before if statements , make sure values expect. example:

console.writeline("values before if statement:") console.writeline (a); console.writeline (b); console.writeline (c); if (a > b && > c) { ... 

again - recommend going breakpoint route, above might quick , dirty way see values if aren't familiar visual studio debugging.

in summary - code should give desired output. problem lies somewhere else.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -