Here is the problem:
Write A Program That Allows You To Enter Cd Names Into An Array Of Strings And The Cd Artist Into An Array Of Strings. At The Beginning Of The Program Prompt The User To Enter The Total Number Of Cd’s Intended To Enter. Max Value Of 20. After Entering The Cd Names And Artists, The Application Should Display The Names And Artists.
***Your Program Must Work Exactly Like The One Shown Below.***
Example Run:
Enter Number Of Cd’s: 3
Enter Name Of Cd 1: The Battle Of Los Angeles
Enter The Artist Of The Battle Of Los Angeles: Rage Against The Machine
Enter Name Of Cd 2: So Far So Good
Enter The Artist Of So Far So Good: Brian Adams
Enter Name Of Cd 3: Amarte Es Un Placer
Enter The Artist Of Amarte Es Un Placer: Luis Miguel
Output:
(Note: Your Output Does Not Need To Line Up Like Mine)
Cd Names Artists
======== ========
The Battle Of Lost Angeles Rage Against The Machine
So Far So Good Brian Adams
Amarte Es Un Placer Luis Miguel
Here is what I have so far in code
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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
#include <iostream>
#include <string>
using namespace std;
int main()
{
//delcare the array
string name[] = {""};
string artist[] = {""};
//decalre variables
int cdCount = 0;
//User input - Total # of Cd's
cout<< "Enter number of CD's: ";
cin.get(cdCount);
//Begin initial selection
if (cdCount < 20 || cdCount == 20)
{
// fill name array with data
for (int sub = 0; sub < cdCount; sub += 1)
{
cout << "Enter name of CD ";
cout << sub + 1<< ": ";
cin.ignore(100,'\n');
cin.getline(name[sub]);
cout << "Enter the artist of ";
cout << name[sub] << ": ";
cin.ignore(100,'\n');
cin.getline(artist[sub]);
}//end for
//display the contents of the array
cout << endl << endl;
for (int sub = 0; sub < cdCount; sub += 1)
{
cout << name[sub];
cout << " by ";
cout << artist[sub];
cout << endl;
}//end for
} //end if
else
cout << "You have exceed the entry limit.";
return 0;
} //end main function
|
I can finally enter the 2nd line So Far So Good, but after I hit enter, the program crashes and does not display "Enter the artist of So far so good"
I'm a little stuck..