Thread: Homework

  1. #1
    Registered User
    Join Date
    Feb 2016
    Posts
    2

    Homework

    Build a program that uses a single-dimension array to store 10 numbers input by a user. After inputting the numbers, the user should see a menu with two options to sort and print the 10 numbers in ascending or descending order.

    This is what I have so far, and I'm stuck.

    Code:
    #include<stdio.h>
    int main(void)
    {
     int iNumbers[10];
     int iEntry=0;
     int x=0;
     
     printf("Enter 10 Numbers");
     
     for (x=0; x<=9; x++) {
      scanf("%d", &iNumbers[x]);
      }
      
     printf("\n\nAscending or Descending Order?");
     printf("\n1)\tAscending\n");
     printf("\n2)\tDescending\n");
     scanf("%d", &iEntry);
     
     for(x = 0; x<=9; x++)
      printf("%d", &iNumbers[x]);
     
     
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Is this supposed to be C or C++? Your code is written in an entirely C style, but you posted in the C++ programming forum.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2016
    Posts
    2
    Quote Originally Posted by laserlight View Post
    Is this supposed to be C or C++? Your code is written in an entirely C style, but you posted in the C++ programming forum.
    It must be C then.

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    The trick is to break down your problem into smaller pieces and solve them one at a time.

    The very next step should be to determine what option the user selected. Do you know how to have your program make a decision? If the user enters 1, then simply print "You selected Ascending." If the user enters 2, then simply print "You selected Descending". You might also want a third branch telling the user if they entered an incorrect option.

    This should be easy enough. Add this basic functionality to the code, post the update, then we can move on to the next piece if you need help from there.

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Stark88: if you want to give the problem a try, by all means, but you should not post a spoonfeeding solution until the original poster has come close enough to a solution on his/her own.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Feb 2016
    Posts
    11
    Sorry ya i figured out that was bad after i've posted it, i'm new here.

  7. #7
    Registered User
    Join Date
    Oct 2015
    Posts
    4
    If you are to print them in order, you'll need to atleast sort them .. heres a basic method
    Bubble Sort and Modified Bubble Sort - Cprogramming.com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Homework help...
    By pSyXaS in forum C Programming
    Replies: 2
    Last Post: 05-08-2011, 02:21 AM
  2. Need help on my homework
    By mejv3 in forum C++ Programming
    Replies: 15
    Last Post: 10-11-2005, 03:43 PM
  3. Homework Help
    By shadowctr in forum C++ Programming
    Replies: 2
    Last Post: 10-03-2005, 07:29 PM
  4. Homework Help Please
    By mars4bb in forum C++ Programming
    Replies: 3
    Last Post: 09-26-2005, 05:16 PM
  5. ok, yes, I need help with my homework!
    By melee in forum C Programming
    Replies: 5
    Last Post: 09-22-2004, 07:42 AM