Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I get an error saying I need a \'While\' ant the getline statement is underlined

ID: 3731507 • Letter: I

Question

I get an error saying I need a 'While' ant the getline statement is underlined. I am just trying to ask the user if they want to run the program again Y/N

Please help with the c++ code

using namespace std;

int main()

{

// Declare variables

string artist, songTitle;

double songLength = 0, playListLength = 0, songlength;

char again;

{

do

//Ask user for Data

cout << "Please enter the artist ";

getline(cin, artist);

cout << "please enter the song title ";

getline(cin, songTitle);

cout << "Please enter the song length ";

cin >> songLength;

// Add song lengths

cout << "The song " << songTitle << " by " << artist << " is " << songLength << " Minutes long ";

cout << "Would you like to continue? (Y/N)";

cin >> again;

while (again == 'Y' || again == 'y');

system("pause");

return 0;

}

Explanation / Answer

Answer : See comments in italic

#include<bits/stdc++.h>

using namespace std;

int main()

{

// Declare variables

string artist, songTitle;

double songLength = 0, playListLength = 0, songlength;

char again;

// { we need to put open curly bracket after do statement

do

{

//Ask user for Data

cout << "Please enter the artist ";

getline(cin, artist);

cout << "please enter the song title ";

getline(cin, songTitle);

cout << "Please enter the song length ";

cin >> songLength;

// Add song lengths

cout << "The song " << songTitle << " by " << artist << " is " << songLength << " Minutes long ";

cout << "Would you like to continue? (Y/N)";

cin >> again;

// curly bracket should be closed for do statement then put curly bracket

}while (again == 'Y' || again == 'y');

system("pause");

return 0;

}