In: Computer Science
How do I stop the comma from printing at the end of Neptune?
#include <iostream>
using namespace std;
int main() {
string planets[] = {"Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune"};
cout << "Contents in the array: ";
for(int i = 0; i < 8 ; i++) {
cout << *(planets + i) << ", ";
}
cout << endl;
return 0;
}
// Screenshot of the code

// Sample output

// Code to copy
#include <iostream>
using namespace std;
int main() {
string planets[] =
{"Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune"};
cout << "Contents in the array: ";
for(int i = 0; i < 8; i++)
{
if(i == 7){
cout <<*(planets + i)<<"
";
}else if(i){
cout << *(planets + i) << ",
";
}
}
cout << endl;
return 0;
}