Question

c ++ CAN NOT use array. write a C++ code that For the Name and Title...

c ++ CAN NOT use array.

write a C++ code that For the Name and Title have the option to randomly select from three different choices. Essentially what this means is that you will have three options that are possible.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

From your question statement what I understood is, You will have select Name from the 3 options and you will have to select Title from 3 options.

What I thought was, when someone wants to enter name, we will show 3 options and ask them to select based on 1 or 2 or 3. and same is the title. Since we cannot use array, I am storing the 3 possible names in variables for both name and title. Below is the code for this explanations. This is how I understood the question, If it is different please provide more explanation.

CODE:

#############################

#include<iostream>
using namespace std;

int main()
{
string name1="JOHN", name2="ALFRED", name3="DAN";
string title1="MR", title2 = "MRS", title3 = "DR";
string name, title;
int n,t;

while(1){
cout<<"Select title: 1."<<title1<<" 2."<<title2<<" 3."<<title3<<": ";
cin>>t;
if(t==1) title=title1;
else if(t==2) title=title2;
else if(t==3) title=title3;
else {
cout<<"WRONG TITLE SELECTED\n";
continue;
}
break;
}

while(1){
cout<<"Select name: 1."<<name1<<" 2."<<name2<<" 3."<<name3<<": ";
cin>>n;
if(n==1) name=name1;
else if(n==2) name=name2;
else if(n==3) name=name3;
else {
cout<<"WRONG NAME SELECTED\n";
continue;
}
break;
}

cout<<"\n\nSelected Name: "<<name<<"\nSelected Title: "<<title<<"\n\n";
}

##############################

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
c ++ CAN NOT use array. write a C++ code that For the Name and Title...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • CAN SOMEONE PLEASE HELP ME WRITE THIS CODE IN C++, PLEASE HAVE COMMENTS IN THE CODE...

    CAN SOMEONE PLEASE HELP ME WRITE THIS CODE IN C++, PLEASE HAVE COMMENTS IN THE CODE IF POSSIBLE!! General Description: Write a program that allows the user to enter data on their friends list. The list holds a maximum of 10 friends, but may have fewer. Each friend has a name, phone number, and email address. The program first asks the user to enter the number of friends (1-10). You are not required to validate the entry, but you may...

  • Three C Code Questions: 5. Write a C program that declares an array of 10 strings,...

    Three C Code Questions: 5. Write a C program that declares an array of 10 strings, each of max length 50 characters, and then reads an entire line of text from the keyboard into each string. 6. Write C code that finds the longest name in this array of strings that you read in Q5. Hint: find the position of the longest string, not the string itself. 7. Write a C program that creates a 4 x 6 two dimensional...

  • 9. Write some C++ code that will fill an array a with 20 values of type...

    9. Write some C++ code that will fill an array a with 20 values of type int read in from the keyboard. You need not write a full program, just the code to do this, but do give the declarations for the array and for all variables. 10. Suppose you have the following array declaration in your program: int your_array[7]; Also, suppose that in your implementation of C++, variables of type int use two bytes of memory. When you run...

  • C Language Write the code that dynamically allocates an array of struct objects based on a...

    C Language Write the code that dynamically allocates an array of struct objects based on a size entered through the command line arguments, You will use the following struct and enum. typedef enum Color { RED, GREEN, BLUE } Color; typedef struct MyStruct { int value; Color color; } MyStruct; Write the code to do the following: a. Check for one additional command line argument. Only proceed to the rest of the program if it exists and that the value...

  • Write a C program Design a program that uses an array to store 10 randomly generated...

    Write a C program Design a program that uses an array to store 10 randomly generated integer numbers in the range from 1 to 50. The program should first generate random numbers and save these numbers into the array. It will then provide the following menu options to the user: Display 10 random numbers stored in the array Compute and display the largest number in the array Compute and display the average value of all numbers Exit The options 2...

  • 1. A college database keeps information about: Professors- ID, Name, Title . Courses - Code, Name...

    1. A college database keeps information about: Professors- ID, Name, Title . Courses - Code, Name . Software products- Name, description For each semester, the college wants to record which professor taught which course and what software was used for it. A particular software product can be used in different courses; a professor can teach more than one course and use multiple software products; a course can be taught by different professors For each software product there is a professor...

  • C# code Arrays and Linked Lists: Write C++/Java/C#/Python code to declare an array of linked lists...

    C# code Arrays and Linked Lists: Write C++/Java/C#/Python code to declare an array of linked lists of any primitive type you want. (Array of size 2020) (This could be based on MSDN libraries or the lab) – you do not need to instantiate any of the linked lists to contain any actual values. Paste your code for that here (this should only be one line) Based on your code or the lab from 4 or your doubly linked list from...

  • #PLEASE WRITE THE CODE IN JAVA! THANK YOU IN ADVANCE! Write a program that manages a...

    #PLEASE WRITE THE CODE IN JAVA! THANK YOU IN ADVANCE! Write a program that manages a list of up to 10 players and their high scores in the computer's memory. Use two arrays to manage the list. One array should store the players' names, and the other array should store the players' high scores. Use the index of the arrays to correlate the names with the scores. Your program should support the following features: a. Add a new player and...

  • I need a Python code for this problem. We can use python's array slicing in many...

    I need a Python code for this problem. We can use python's array slicing in many ways, and here is just one example. To take the forward derivative of an array y, we use (y[i+1] - y[i])/dx For example, if dx=1 , we might write a derivative routine as yderiv = zeros (len(y)-1) for i in range(len(y)-1): yderiv[i] = y(i+1] - y[i] Note that here, yderiv is one element shorter than y -- this is because you need 2 points...

  • Write the code in PYTHON and please provide the full code, thank you! Write a program...

    Write the code in PYTHON and please provide the full code, thank you! Write a program that plots two functions: f(x) = x2 and g(x) = ax. Write it in such a way that the intersection points are marked with an X, for arbitrary a. • You may use your favorite ready-made function to find the intersection points, if not: • One possible way to tackle this problem is to put both function values in arrays and check using a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT