Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have written this C++ program. When you enter artist, song and song length it asks if I want to enter another, so i enter

I have written this C++ program. When you enter artist, song and song length it asks if I want to enter another, so i enter y for yes and I enter the same information. Now when it asks if i want to add another song i hit no and select display play list option. It shows the playlist but the name of the artists from the play list is missing

please help.

all information for the items entered shoud be displayed.

// week 3 with menu.cpp : Defines the entry point for the console application.

//Richard Wooten

//Week 4 program added loop and started arrays

//

#include "stdafx.h"

# include

# include

# include

using namespace std;

struct music

{

string title;

string artist;

float len;

};

int main()

{

music arr_str[20];

string artist1, songTitle1, artist2, songTitle2;

float totalLength = 0;

char again;

int ch, i = -1;

// get data

while (1)

{

cout << "1. Add songs" << endl;

cout << "2. Display songs" << endl;

cout << "3. Exit" << endl;

cout << "Enter your choice : ";

cin >> ch;

switch (ch)

{

case 1:

while (1)

{

++i;

cin.clear();

cout << "Insert the artist name of the first song: ";

getline(cin, arr_str[i].artist);

cin.ignore(1000, ' ');

cout << "Insert the title of the first song: ";

getline(cin, arr_str[i].title);

cout << "Insert the length of the first song: ";

cin >> arr_str[i].len;

totalLength = totalLength + arr_str[i].len;

cout << " Would you like to add another? y/n : ";

cin >> again;

if (again == 'n' || again == 'N')

break;

}

break;

case 2:

if (i == -1)

{

cout << "No songs found" << endl;

}

else

{

for (int k = 0; k <= i; k++)

{

cout << " Artist:\t" << arr_str[k].artist << " ";

cout << " Title: \t" << arr_str[k].title << " ";

cout << " Length:\t" << arr_str[k].len << " ";

}

cout << "The playlist has a total length of " << totalLength << " minutes. ";

}

break;

case 3:

cout << " *** System will now exit ***" << endl;

exit(0);

}

}

system("pause");

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Watson Watson

5th Edition

0471715360, 978-0471715368

More Books

Students also viewed these Databases questions

Question

what is A/P

Answered: 1 week ago