Question

USE C++ TO DEVELOP THE CODE. THANKS IN ADVANCE create an array of strings with a...

USE C++ TO DEVELOP THE CODE. THANKS IN ADVANCE

create an array of strings with a size of 10.
explain the story to the player, whatever story you wish to tell.
the player starts with 3 items.
over the course of several adventures, 
1.  the player gains 3 items and has to name each of them.
for example: BunnySword or FlameGuitar
- because of cin limitations, the name can only be one word.
2.  the player uses 1 item, making it go away.
3. at each change in inventory - show the changes with a for loop that ignores strings that have "" no characters.   
For the final challenge, the player must give up their most treasured item to the bridge troll (or similar) to get past the bridge.
The player will have to search for that item inside of a for loop.

Beyond the Requirements
  1. Create dialogue that makes the program feel more intuitive
  2. Use a while or do-while loop to ensure that the player successfully finds an item before moving past the bridge.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE:

#include <iostream>

#include <string>

using namespace std;

// print the string array

void print(string player[]){

  cout<<"\nYour current items are:\n";

  for(int i=0;i<10;i++){

    if(!player[i].empty())

    cout<<"\n"<<player[i]<<"\n";

  }

}

// delete one item from the array

void loose(string player[]){

  cout<<"\nLost 1 item\n";

  // loose one item

  for(int i=0;i<10;i++){

    if(!player[i].empty())

    {

      player[i].clear();

      break;

    }

  }

  print(player);

}

// add 3 items in the array

void gain(string player[]){

  cout<<"You gained 3 items\n";

  // gain 3 items

  int n=3;

  string item;

  while(n--){

    cout<<"Enter item name:\n";

    cin>>item;

    for(int i=0;i<10;i++){

      if(player[i].empty()){

        player[i]=item;

        break;

      }

    }

  }

  print(player);

}

int main() {

  string player[10];

  // hard coding 3 items in the start of the game

  player[0]="BunnySword";

  player[1]="Ironman";

  player[2]="ninja";

  char ch;

  

  do{

    gain(player);

    loose(player);

    cout<<"\nDo you wish to continue the adventure(Y/N): "<<endl;

    cin>>ch;

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

}

OUTPUT:

Please upvote if you like my answer and comment below if you have any queries.

Add a comment
Know the answer?
Add Answer to:
USE C++ TO DEVELOP THE CODE. THANKS IN ADVANCE create an array of strings with a...
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
  • c++ can use if else, loop,function ,array,file i.o. Can not use swtich, global variables etc..   Please...

    c++ can use if else, loop,function ,array,file i.o. Can not use swtich, global variables etc..   Please do all parts. previously I post 3 time for part1 ,2 and 3 but I can't make it into one complete program code. I even try to post a questions ask and post the 3 parts of code for experts to put it together. But experts said it's not enough information. please help... Thank you ! Program Objectives: Allow students to create arrays Allow...

  • Need this in C The starter code is long, if you know how to do it...

    Need this in C The starter code is long, if you know how to do it in other way please do. Do the best you can please. Here's the starter code: // ----------------------------------------------------------------------- // monsterdb.c // ----------------------------------------------------------------------- #include #include #include // ----------------------------------------------------------------------- // Some defines #define NAME_MAX 64 #define BUFFER_MAX 256 // ----------------------------------------------------------------------- // Structs typedef struct { char name[NAME_MAX]; int hp; int attackPower; int armor; } Character; typedef struct { int size; Character *list; } CharacterContainer; // ----------------------------------------------------------------------- //...

  • In C++ Do not use a compiler like CodeBlocks or online. Trace the code by hand....

    In C++ Do not use a compiler like CodeBlocks or online. Trace the code by hand. Do not write "#include" and do not write whole "main()" function. Write only the minimal necessary code to accomplish the required task.                                                                                                           Save your answer file with the name: "FinalA.txt" 1) (2 pts) Given this loop                                                                                              int cnt = 1;     do {     cnt += 3;     } while (cnt < 25);     cout << cnt; It runs ________ times    ...

  • Consider the following C++ program. It reads a sequence of strings from the user and uses...

    Consider the following C++ program. It reads a sequence of strings from the user and uses "rot13" encryption to generate output strings. Rot13 is an example of the "Caesar cipher" developed 2000 years ago by the Romans. Each letter is rotated 13 places forward to encrypt or decrypt a message. For more information see the rot13 wiki page. #include <iostream> #include <string> using namespace std; char rot13(char ch) { if ((ch >= 'a') && (ch <= 'z')) return char((13 +...

  • Instructions: Consider the following C++ program. It reads a sequence of strings from the user and...

    Instructions: Consider the following C++ program. It reads a sequence of strings from the user and uses "rot13" encryption to generate output strings. Rot13 is an example of the "Caesar cipher" developed 2000 years ago by the Romans. Each letter is rotated 13 places forward to encrypt or decrypt a message. For more information see the rot13 wiki page. #include <iostream> #include <string> using namespace std; char rot13(char ch) { if ((ch >= 'a') && (ch <= 'z')) return char((13...

  • Using C++ in Visual Studios Rewrite the code to use a Stack instead of a Queue....

    Using C++ in Visual Studios Rewrite the code to use a Stack instead of a Queue. You will need to think about the differences in the Stack and Queue. Think about how they operate and how the nodes may differ.   Modify the code as necessary. You will need to push to the Stack, pop from the Stack, peek at the Stack. You will need a member functions like in the example code. Your program will need to show that everything...

  • I've posted 3 classes after the instruction that were given at start You will implement and...

    I've posted 3 classes after the instruction that were given at start You will implement and test a PriorityQueue class, where the items of the priority queue are stored on a linked list. The material from Ch1 ~ 8 of the textbook can help you tremendously. You can get a lot of good information about implementing this assignment from chapter 8. There are couple notes about this assignment. 1. Using structure Node with a pointer point to Node structure to...

  • In Java plz due today Assignment 4 - Email, Shwitter and Inheritance Select one option from...

    In Java plz due today Assignment 4 - Email, Shwitter and Inheritance Select one option from below. All (both) options are worth the same number of points. The more advanced option(s) are provided for students who find the basic one too easy and want more of a challenge. OPTION A (Basic): Message, EMail and Tweet Understand the Classes and Problem Every message contains some content ("The British are coming! The British are coming!"). We could enhance this by adding other...

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