Answer to Question #175668 in C++ for Jeremy

Question #175668

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 


1
Expert's answer
2021-03-26T03:50:07-0400
#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');
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS