# Getting The Largest Number! Need Help ASAP!!

Discussion in 'C#' started by akia, Feb 12, 2009.

1. ### akiaNew Member

Joined:
Feb 12, 2009
Messages:
8
0
Trophy Points:
0
http://www.myspace.com/lil_buttin_up
I need help coding a C Sharp Program that obtains three numbers from the user and displays which number is the largest!!

-Akia Chenise

2. ### NewsBotNew Member

Joined:
Dec 2, 2008
Messages:
1,267
2
Trophy Points:
0
Looks pretty simple. Have you tried anything with it.

3. ### akiaNew Member

Joined:
Feb 12, 2009
Messages:
8
0
Trophy Points:
0
http://www.myspace.com/lil_buttin_up
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);

This is what I have tried but Im not even sure if this is right....can some one help??

4. ### NewsBotNew Member

Joined:
Dec 2, 2008
Messages:
1,267
2
Trophy Points:
0
Do some test run and see if it gives correct results.

5. ### akiaNew Member

Joined:
Feb 12, 2009
Messages:
8
0
Trophy Points:
0
http://www.myspace.com/lil_buttin_up
...It doesn't....do you know what I am doing wrong?

6. ### NewsBotNew Member

Joined:
Dec 2, 2008
Messages:
1,267
2
Trophy Points:
0
How are you taking the input and also what were the test run sample which gave wrong results

7. ### akiaNew Member

Joined:
Feb 12, 2009
Messages:
8
0
Trophy Points:
0
http://www.myspace.com/lil_buttin_up
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);

8. ### NewsBotNew Member

Joined:
Dec 2, 2008
Messages:
1,267
2
Trophy Points:
0
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.

9. ### akiaNew Member

Joined:
Feb 12, 2009
Messages:
8
0
Trophy Points:
0
http://www.myspace.com/lil_buttin_up
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);

tthis is the right one

What do I do Next?

10. ### NewsBotNew Member

Joined:
Dec 2, 2008
Messages:
1,267
2
Trophy Points:
0
Refer to the function console.ReadLine first to get the input from the user.

How did you get tha code ?

11. ### akiaNew Member

Joined:
Feb 12, 2009
Messages:
8
0
Trophy Points:
0
http://www.myspace.com/lil_buttin_up
someone started it off for me...is it right

12. ### NewsBotNew Member

Joined:
Dec 2, 2008
Messages:
1,267
2
Trophy Points:
0
You should understand what it does.

13. ### akiaNew Member

Joined:
Feb 12, 2009
Messages:
8
0
Trophy Points:
0
http://www.myspace.com/lil_buttin_up
I dont...that is why im here.. I need help..

14. ### NewsBotNew Member

Joined:
Dec 2, 2008
Messages:
1,267
2
Trophy Points:
0

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.

15. ### akiaNew Member

Joined:
Feb 12, 2009
Messages:
8
0
Trophy Points:
0
http://www.myspace.com/lil_buttin_up
Thats what I mean I dont understand where i messed up at all...I am confused...

16. ### NewsBotNew Member

Joined:
Dec 2, 2008
Messages:
1,267
2
Trophy Points:
0
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.

17. ### AidanPaineNew Member

Joined:
Feb 26, 2009
Messages:
24
0
Trophy Points:
0
Occupation:
Security Guard
Location:
NY
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!

18. ### AidanPaineNew Member

Joined:
Feb 26, 2009
Messages:
24
0
Trophy Points:
0
Occupation:
Security Guard
Location:
NY
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?

19. ### johny_1015_1981New Member

Joined:
Oct 5, 2008
Messages:
19
0
Trophy Points:
0
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);

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 !