hi guys, pls help me with this problem

This is a discussion on hi guys, pls help me with this problem within the C++ Programming forums, part of the General Programming Boards category; i am supposed to create a program in c++ that would a) Prompt the user to input a string of ...

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    7

    Thumbs up hi guys, pls help me with this problem

    i am supposed to create a program in c++ that would
    a) Prompt the user to input a string of characters up to a maximum of 40 characters

    b) Read the string input from the keyboard

    c) Output the sequence of characters in alphabetical order

    d) Prompt the user to repeat the process if desired



    i have created program and tried it on c++ but there is error saying eh.h is not in c++.


    here is the code:


    Code:
     
    #include <iostream> 
    #include <string> 
    using namespace std; 
    
    const int MAXSIZE = 9; 
    char* names[MAXSIZE] = { "a", "c", "d", "f", "i", "b", "e", "g", "h" }; 
    char* tmp; 
    
    void start(); 
    void decSort(char* arr[], int size); 
    void ascSort(char* arr[], int size); 
    void runAgain(); 
    
    int main() 
    { 
    
     start(); 
     return 0; 
    } 
    
    void start() 
    { 
     int k, choice; 
     cout << "Press 1 to sort in decending order: \n"; 
     cout << "Press 2 to sort in ascending order: \n"; 
     cin >> choice; 
    
     if(choice == 1) 
     { 
      cout << "------------\n"; 
      cout << "Before Sort: \n"; 
      cout << "------------\n"; 
      for(k = 0;k < MAXSIZE;k++) 
      cout << names[k] << "\n"; 
    
      decSort(names, MAXSIZE); 
      cout << "------------\n"; 
      cout << "After Sort: \n"; 
      cout << "------------\n"; 
      for(k = 0;k < MAXSIZE;k++) 
      cout << names[k] << "\n"; 
      runAgain(); 
     } 
    
     else if(choice == 2) 
     { 
      cout << "------------\n"; 
      cout << "\nBefore Sort: \n"; 
      cout << "------------\n"; 
      for(k = 0;k < MAXSIZE;k++) 
      cout << names[k] << "\n"; 
    
      ascSort(names, MAXSIZE); 
      cout << "------------\n"; 
      cout << "\nAfter Sort: \n"; 
      cout << "------------\n"; 
      for(k = 0;k < MAXSIZE;k++) 
      cout << names[k] << "\n"; 
      runAgain(); 
     } 
    } 
    
    void decSort(char* arr[], int size) 
    { 
     for(int i = 0; i < size - 1;i++) 
     for(int j = 0; j < size - 1 - i;j++) 
     { 
      if(strcmp(arr[j], arr[j + 1]) < 0) 
      { 
       tmp = arr[j]; 
       arr[j] = arr[j + 1]; 
       arr[j + 1] = tmp; 
      } 
     } 
    } 
    
    void ascSort(char* arr[], int size) 
    { 
     for(int i = 0; i < size - 1;i++) 
      for(int j = 0; j < size - 1 - i;j++) 
      { 
       if(strcmp(arr[j], arr[j + 1]) > 0) 
       { 
        tmp = arr[j]; 
        arr[j] = arr[j + 1]; 
        arr[j + 1] = tmp; 
       } 
     } 
    
    }

    PLs can anyone find the error or help me out?????!!!!!!!!!

  2. #2
    Registered User ventolin's Avatar
    Join Date
    Jan 2004
    Posts
    92
    Remove the calls to runAgain and it works fine. Eg:

    Code:
     
    
    //void runAgain();
    
      ....
      for(k = 0;k < MAXSIZE;k++) 
      cout << names[k] << "\n"; 
       //runAgain();
     } 
     ....
     
     .....
      for(k = 0;k < MAXSIZE;k++) 
      cout << names[k] << "\n"; 
      //runAgain();
     } 
    }
    Think of a better way to loop the program if you need to do so, or instead call :

    Code:
    start();

  3. #3
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,088
    A couple of things that might help you:

    Give us the exact error message. What is eh.h? It is not mentioned in the code, so maybe there is code that you haven't posted, or maybe the actual error message has better information.

    The code you posted uses a function called runAgain(), but that function is not defined anywhere. Either you didn't post it or you didn't define it. As ventolin said, if you remove the calls, the program runs, although it doesn't do what your requirements state it should.

    So if you are getting compiling or linking errors, post the exact errors, and make sure that all your code is posted, or at least a complete example that shows the problem.

    P.S. A more descriptive title for your thread would be nice. "Help please" tends to turn people off to a thread.

    P.P.S. Congratulations on learning how to use code tags, now make sure to read the other stickied posts and FAQs. They'll help you better and likely faster than we will.
    Last edited by jlou; 05-18-2004 at 06:35 PM.

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Try this.
    Code:
    void start() 
    { 
     int k, choice; 
     cout << "Press 1 to sort in decending order: \n"; 
     cout << "Press 2 to sort in ascending order: \n"; 
     cin >> choice; 
    
     while (choice >= 1 && choice <=2)
     {
      if(choice == 1) 
      { 
       cout << "------------\n"; 
       cout << "Before Sort: \n"; 
       cout << "------------\n"; 
       for(k = 0;k < MAXSIZE;k++) 
        cout << names[k] << "\n"; 
    
       decSort(names, MAXSIZE); 
       cout << "------------\n"; 
       cout << "After Sort: \n"; 
       cout << "------------\n"; 
       for(k = 0;k < MAXSIZE;k++) 
       cout << names[k] << "\n"; 
      } 
    
      else if(choice == 2) 
      { 
       cout << "------------\n"; 
       cout << "\nBefore Sort: \n"; 
       cout << "------------\n"; 
       for(k = 0;k < MAXSIZE;k++) 
        cout << names[k] << "\n"; 
    
       ascSort(names, MAXSIZE); 
       cout << "------------\n"; 
       cout << "\nAfter Sort: \n"; 
       cout << "------------\n"; 
       for(k = 0;k < MAXSIZE;k++) 
        cout << names[k] << "\n"; 
      }
      cout << "Press 1 to sort in decending order: \n"; 
      cout << "Press 2 to sort in ascending order: \n"; 
      cin >> choice; 
     }
    }

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Funny how this thread looks exactly the same as Sikander's.

  6. #6
    Registered User
    Join Date
    May 2004
    Posts
    7
    thanks mate for your advice.

  7. #7
    Registered User
    Join Date
    May 2004
    Posts
    7

    Thumbs up maths in c++

    what does it mean :---------
    explain the elements of your program design including pseudo-code for your sorting algorithm.

  8. #8
    Registered User
    Join Date
    May 2004
    Posts
    7

    i love aishwarya

    aishwarya

  9. #9
    Registered User
    Join Date
    May 2004
    Posts
    7

    maths in c++

    what does this mean???????!!!!!!!!!!!![FONT=Arial Black][SIZE=4][COLOR=Red]
    discuss the elements used in pseucode sorting algorithm.

  10. #10
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >what does this mean???????!!!!!!!!!!!!
    Excessive ? and ! won't make us want to help you any more than normal.

    >discuss the elements used in pseucode sorting algorithm.
    It means, "Why did you do what you did?"
    My best code is written with the delete key.

  11. #11
    Registered User ventolin's Avatar
    Join Date
    Jan 2004
    Posts
    92
    i just want to know what

    Aishwarya
    is....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Link Lists. I need Some Problem From u Guys to do!
    By Matus in forum C Programming
    Replies: 17
    Last Post: 11-18-2008, 02:06 AM
  2. WSAD Problem Pls Help
    By Ti22 in forum Game Programming
    Replies: 1
    Last Post: 01-16-2005, 10:24 AM
  3. a small problem......plz help me out guys!!!!!!
    By galmca in forum C Programming
    Replies: 13
    Last Post: 11-07-2004, 12:33 AM
  4. Simple problem for you guys - school proj
    By ryancsutton in forum C++ Programming
    Replies: 7
    Last Post: 10-01-2002, 03:06 PM
  5. Spot the problem..a test question, pls help!
    By Unregistered in forum C++ Programming
    Replies: 10
    Last Post: 02-05-2002, 12:40 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21