Conditional Expression Help

I need to add at least one condition expression to my program. I am having trouble with this and hoping someone can nudge me in the right direction. This is my coding so far for my program...

#include <iostream>
#include <string>

using namespace std;

int main()
{

string pName;
string sTitle1, sTitle2, sTitle3;
string sArtist1, sArtist2, sArtist3;
string sGenre1, sGenre2, sGenre3;
float sLength1, sLength2, sLength3;
float totalLength;
float playlistAverage;


cout << "############################################################\n";
cout << " Welcome to the DJ Dance Playlist Manager\n";
cout << "############################################################\n\n\n";


cout << "Insert a name for this playlist: ";
getline (cin, pName);


cout << "Insert the title of the first song: ";
getline (cin, sTitle1);
cout << "Insert the artist name of the first song: ";
getline (cin, sArtist1);
cout << "Insert the genre of the first song: ";
getline (cin, sGenre1);
cout << "Insert the length of the first song: ";
cin >> sLength1;
fflush(stdin);


cout << "\nInsert the title of the second song: ";
getline (cin, sTitle2);
cout << "Insert the artist name of the second song: ";
getline (cin, sArtist2);
cout << "Insert the genre of the second song: ";
getline (cin, sGenre2);
cout << "Insert the length of the second song: ";
cin >> sLength2;
fflush(stdin);


cout << "\nInsert the title of the third song: ";
getline (cin, sTitle3);
cout << "Insert the artist name of the third song: ";
getline (cin, sArtist3);
cout << "Insert the genre of the third song: ";
getline (cin, sGenre3);
cout << "Insert the length of the third song: ";
cin >> sLength3;




totalLength = sLength1 + sLength2 + sLength3;
playlistAverage = sLength1 + sLength2 + sLength3 / 3;

cout << "Name of the playlist: " << pName << "\n\n";
cout << "1.--------------------------------------\n";
cout << " Title: \t" << sTitle1 << "\n";
cout << " Artist:\t" << sArtist1 << "\n";
cout << " Genre: \t" << sGenre1 << "\n";
cout << " Length:\t" << sLength1 << "\n\n";

cout << "2.--------------------------------------\n";
cout << " Title: \t" << sTitle2 << "\n";
cout << " Artist:\t" << sArtist2 << "\n";
cout << " Genre: \t" << sGenre2 << "\n";
cout << " Length:\t" << sLength2 << "\n\n";

cout << "3.--------------------------------------\n";
cout << " Title: \t" << sTitle3 << "\n";
cout << " Artist:\t" << sArtist3 << "\n";
cout << " Genre: \t" << sGenre3 << "\n";
cout << " Length:\t" << sLength3 << "\n\n";

cout << "The playlist named " << pName << " has a total length of " << totalLength << " minutes.";
cout << "Also, the playlist named " << pName << " has an average length of " << playlistAverage << "minutes";
}
Where do you want to add a condition in your program?

Assuming you want to add it to the display

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 
    cout << "Choose one of the songs to see details" << endl;
    cout << " 1 : " << sTitle1 << endl;
    cout << " 2 : " << sTitle2 << endl;
    cout << " 3 : " << sTitle3 << endl;
    cout << " 4 : Exit program   " << endl;

    int choice = 0;

    cout << "Your choice: "; 
    cin>>choice;
    switch(choice)
    {
        case 1:
         // do stuff for songTitle1
        break;
        case 2: 
        // do stuff for songTitle2
        break;
        case 3: 
        // do stuff for songTitle2
        break;
        case 4: 
        cout << "Exiting program... << endl;
        break; 
    } 


NB:
If you provide a better problem description (describe what you intend to achieve), you will get a better response.

In the main time check this http://www.cplusplus.com/doc/tutorial/control/ [sections Selection statements: if and else and Another selection statement: switch.]

or read here
if else statements https://www.tutorialspoint.com/cplusplus/cpp_if_else_statement.htm

switch statements https://www.tutorialspoint.com/cplusplus/cpp_switch_statement.htm

Hope you can now get started
Last edited on
Topic archived. No new replies allowed.