Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Currently, I am trying to prompt the user to choose an album but my code is giving every album available How do I make the

Currently, I am trying to prompt the user to choose an album but my code is giving every album available How do I make the program show The album and its song that the user picked instead of all of the albums and songs showing up? I am using C# in Visual studios. here is my Code we are doing Adv Dictionaries

using System; using System.Collections.Generic; class Program { static void Main(string[] args) { /*

Dictionary> albumName = new Dictionary>() {

//Create the starting value /albums {"Dangerously in Love", new List() }, {"BDAY" , new List() }, {"4", new List() }, {"I Am...Sasha Fierce",new List() }

};

//Enter in the songs in the album albumName["Dangerously in Love"].Add("Naughty Girl"); albumName["Dangerously in Love"].Add("Crazy In Love"); albumName["Dangerously in Love"].Add("Signs"); albumName["Dangerously in Love"].Add("Baby Boy");

//Second Album Songs albumName["I Am...Sasha Fierce"].Add("Halo"); albumName["I Am...Sasha Fierce"].Add("Single Ladies"); albumName["I Am...Sasha Fierce"].Add("Sweet Dreams"); albumName["I Am...Sasha Fierce"].Add("Diva");

//Thrd Albums Song Names albumName["BDAY"].Add("Upgrade U"); albumName["BDAY"].Add("Irreplaceable"); albumName["BDAY"].Add("Beautiful Liar"); albumName["BDAY"].Add("Get Me Bodied");

//Create the last album song list albumName["4"].Add("Run The World"); albumName["4"].Add("Best Thing I Never Had"); albumName["4"].Add("Dance For You"); albumName["4"].Add("1+1");

Console.WriteLine("Choose an Album and I will tell you all the songs on the Album.");

//prompt user to choose an Album Console.WriteLine(" Pick an Album:"); string pickAlbum = Console.ReadLine();

//Validation while (string.IsNullOrWhiteSpace(pickAlbum)) {

//Tell user the error Console.WriteLine(" Please only choose from the album list!"); //repeat the statement Console.WriteLine("Pick an Album:"); //catch users response pickAlbum = Console.ReadLine();

}

foreach ( KeyValuePair> album in albumName) {

//Loop through each dictionary element!Once for each key Console.WriteLine("The Album {0} has the following songs:",album.Key);

//Create second foreach loop that will cycle through foreach (string song in album.Value) { Console.WriteLine(song); }

}

} } }

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions