Do a C++ code to create the following output using only two or more parallel arrays:
Create two parallel arrays, one for actors or actresses and one for their phone numbers with the following data:
Actors: Angelina Jolie, Brad Pitt, Margot Robbie, George Clooney, Jennifer Lopez, Jennifer Lawrence
Info: 949-232-1124, 949-865-3492, 864-235-7569", 939-453-2288, 987-209-2132, 543-239-8745
Prompt the user for a number from 1 to 6 and based on the number, display the actor’s name and related phone number. If the number is not between 1 to 6, an error message as you see below should be displayed.
You should prompt the user if he or she likes to continue and upon Y or y you clear the screen and repeat until the response is N or n
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
void cls() {
for (int i=0; i<35; i++)
cout << endl;
}
int main() {
string Actors[] = { "Angelina Jolie", "Brad Pitt",
"Margot Robbie", "George Clooney",
"Jennifer Lopez", "Jennifer Lawrence" };
string Info[] = { "949-232-1124", "949-865-3492",
"864-235-7569", "939-453-2288",
"987-209-2132", "543-239-8745" };
char ans = 'Y';
while (ans == 'Y') {
int n;
cls();
cout << "Please enter a number betwwen 1 and 6: ";
cin >> n;
if (n < 1 || n > 6) {
cout << "Wrong number" << endl;
}
else {
cout << Actors[n-1] << ": " << Info[n-1] << endl;
}
do {
cout << "Whould you like to continue? (y/n) ";
cin >> ans;
ans = toupper(ans);
} while (ans != 'Y' && ans != 'N');
}
}
Comments
Leave a comment