Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

kris100

  • 3 years ago

how to make a program in c++[using Array] that ask the user to input 9 letters and arrange it in alphabetical order. thanks!

  • This Question is Closed
  1. chamoda
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    #include <iostream> #include <string> using namespace std; int main() { string str = ""; cout << "input : "; cin >> str; { for(int i = 0; i < str.size(); i++) { for(int j = i + 1; j < str.size(); j++) { if(str[i] > str[j]) { char temp = str[i]; str[i] = str[j]; str[j] = temp; } } } cout << "output: " << str << "\n"; } }

  2. across
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Here's an implementation that's more specific (it uses an array of characters, not a string object): http://ideone.com/LqqJgD

  3. kris100
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    when i tried your program the output is equal to the imputed char. the program should arranged the imputed char in to alphabetical order.??

  4. across
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Whose program?

  5. kris100
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    The code you posted. when i started debugging it works fine. but when i started imputing letters the output didn't satisfies the problem. it did not arrange the imputed letters into alphabetical order. it only prints the first char imputed.i don't know what's wrong with it.

  6. across
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    The code is working correctly with the Ideone compiler. Perhaps your input is incorrect?

  7. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy