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?

#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;

}
2
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by HoldenCfld
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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.