| | |
String sorting troubles
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2007
Posts: 6
Reputation:
Solved Threads: 0
I have to take in a list of song names. When the user types in "mmm" then it stops, and it spits out the first and last song titles in a sorted list (alphabetically). This is what I came up with, and there's many an error, all seemingly bool errors.
So, any suggestions?
So, any suggestions?
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> using namespace std; int main() { string songTitles; int songMax = 0; int songMin = 0; while (songTitles != "mmm") { cout << "Please enter a song title: "; getline (cin, "songTitle") if (songTitles != "mmm") songTitles = songMin; if (songTitles < songMin && songTitles != "mmm") songTitles = songMin; if (songTitles > songMin && songTitles != "mmm") songTitles = songMax; if (songTitles > songMax && songTitles != "mmm") songTitles = songMax; } cout << "First song: " << songMin; cout << "Last song: " << songMax; return 0; }
How are the integers songMin and songMax going to hold the titles of the respective first and last titles?
Your branching code should be done as a series of if...else if statements - when any one of the three (not four) possible conditions is met, there's no point in continuing testing.
Look at the order of the assignments you make. Remember that Left hand side is assigned what's on the Right hand side. ( LHS <- RHS )
See my comments on min/max testing in an earlier thread.
Your branching code should be done as a series of if...else if statements - when any one of the three (not four) possible conditions is met, there's no point in continuing testing.
Look at the order of the assignments you make. Remember that Left hand side is assigned what's on the Right hand side. ( LHS <- RHS )
See my comments on min/max testing in an earlier thread.
![]() |
Similar Threads
- very strange string behaviur.. (C)
- Sorting string data (C++)
- Sort a dynamic array of structs (Visual Basic 4 / 5 / 6)
- Problem of sorting words of each string using pointers (C++)
- sort string in file txt (C++)
- sorting an array of string (C)
- sorting 2d arrays (C)
Other Threads in the C++ Forum
- Previous Thread: Explicit template instantiation
- Next Thread: Converting a String to an int array
Views: 617 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






