Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

kris100

  • 2 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
    • 2 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
    • 2 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
    • 2 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
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Whose program?

  5. kris100
    • 2 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
    • 2 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.

    Search OpenStudy
    • Attachments:

Ask your own question

Ask a Question
Find more explanations on OpenStudy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.