Getting The Largest Number! Need Help ASAP!!

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

  1. akia

    akia New Member

    Joined:
    Feb 12, 2009
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    http://www.myspace.com/lil_buttin_up
    :confused: 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
     
  2. NewsBot

    NewsBot New Member

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

    akia New Member

    Joined:
    Feb 12, 2009
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    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);
    Console.ReadLine();

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

    NewsBot New Member

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

    akia New Member

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

    NewsBot New Member

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

    akia New Member

    Joined:
    Feb 12, 2009
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    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. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    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. akia

    akia New Member

    Joined:
    Feb 12, 2009
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    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);
    Console.ReadLine();

    tthis is the right one

    What do I do Next?
     
  10. NewsBot

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    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. akia

    akia New Member

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

    NewsBot New Member

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

    akia New Member

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

    NewsBot New Member

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

    akia New Member

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

    NewsBot New Member

    Joined:
    Dec 2, 2008
    Messages:
    1,267
    Likes Received:
    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. AidanPaine

    AidanPaine New Member

    Joined:
    Feb 26, 2009
    Messages:
    24
    Likes Received:
    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. AidanPaine

    AidanPaine New Member

    Joined:
    Feb 26, 2009
    Messages:
    24
    Likes Received:
    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_1981

    johny_1015_1981 New Member

    Joined:
    Oct 5, 2008
    Messages:
    19
    Likes Received:
    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);
    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();
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice