I need help coding a C Sharp Program that obtains three numbers from the user and displays which number is the largest!! Please help! -Akia Chenise
int largestNum = 0; int[] numbers = new int[3]; for (int i = 0; i < 3; i++) { if (numbers > largestNum) largestNum = numbers; } Console.WriteLine("The largest number is ", largestNum); Console.ReadLine(); This is what I have tried but Im not even sure if this is right....can some one help??
wHAT DO yOU MEAN? Do You Mean This: number; as array largnum = number[0]; for(i=1;number.length<i;i=i+1) { if (number>largnum) { largnum = number; } } Console.writeline("largest number {0}", largnum);
In the code you posted there is no place for user input like console.ReadLine Also you told the answer it gave is wrong and so wanted to know what input you gave and answer was wrong.
int largestNum = 0; int[] numbers = new int[3]; for (int i = 0; i < 3; i++) { if (numbers > largestNum) largestNum = numbers; } Console.WriteLine("The largest number is ", largestNum); Console.ReadLine(); tthis is the right one What do I do Next?
Refer to the function console.ReadLine first to get the input from the user. How did you get tha code ?
We cannot write your programs. We can help if you try to help you. It would take less time to write the program that this post but this forum is not for doing such tasks but if you understand the problem and know how to get around we can help you in the process. Again if I give you the code and some enhancement is needed you would still be doing the same. Instead go for some books and get the programs yourself.
You have not messed up. You lag the basic of how to take the input from the user as well. First write a program to get 3 user inputs.
I might not know what I'm doing, but I need the practice, so I'll try to help. I'm going to write this code down and see what happens. If it stumps me and my head asplodes, oh well. but If I solve it WHOO HOO!
I think that I'm missing something. This is absolutely beyond my scope. logically, before putting this in, I think theres and issue with congruity. If largest number is greater than the largest number, the number should be 3, right?
int largestNum = 0; int[] numbers = new int[3]; for (int i = 0; i < 3; i++) { if (numbers > largestNum) largestNum = numbers; } Console.WriteLine("The largest number is ", largestNum); Console.ReadLine(); The problem with the code above is if all values are less then zero i.e. all values are negetive then the The program would display 0 as large number and after the 2nd line add a code segment to read the values. values are not set. after reading all three number add this line largestNum=numbers[0]; and then change the for loop like this for(int i=1;i<3;i++) so the entire code would be int largestNum; int[] numbers = new int[3]; //numbers are declared but no value is set yet ! /*instrction to read numbers*/ largestNum=numbers[0]; for (int i = 1; i < 3; i++) { if (numbers > largestNum) largestNum = numbers; } Console.WriteLine("The largest number is ", largestNum); Console.ReadLine();