Best writers. Best papers. Let professionals take care of your academic papers

Order a similar paper and get 15% discount on your first order with us
Use the following coupon "FIRST15"
ORDER NOW

I need help with these questions and I only have $40.

I need help with these questions and I only have $40. I hope you can help me…
This is the

code and this is what I don’t understand how to do…….□    to fill in the two lines that create the arrays and initialize them to 0.

#include <iostream> // gives us access to cout and cin

#include <time.h> // needed to access time for the random number seed.

using namespace std;// Without this, we would have to use std:: with cout, cin, and endl. (e.g std::cout)

//***—Week 2 iLab Part A: Working with Arrays—***

int main()

{

      // Create two initialized variables for an array of 10 ints

      // ADD YOUR CODE HERE

      // Generate a random number seed

      srand(time(0));

      // variables to save the left and right wins

      int leftCount = 0;

      int rightCount = 0;

      // Use a for loop to get random numbers (1-8) into the array

      // (we’ll cover the for loop next week)

      for (int index = 0; index < 10; index++)

      {     

             left[index] = rand()%8 + 1; // Store random number in left

             right[index] = rand()%8 + 1;// Store random number in right

      }

      cout << “Let the battle begin!” << endl;

      for (int index = 0; index < 10; index++)

      {

             bool leftWin = false;

             bool rightWin = false;

             cout << “left[” << index << “] = ” << left[index] << ” right[” << index << “] = ” << right[index] << endl;            

             int sum = left[index] + right[index]; //add the two values

             if (sum > 8)

             {

                    leftCount++;

                    leftWin = true;

             }

             if (sum%2 == 0)

             {

                    rightCount++;

                    rightWin = true;

             }

             if (leftWin && rightWin)

             {

                    cout << “Both win, so round “<< index << ” is a tie.” << endl;

             }

             else if (leftWin)

             {

                    cout << “Left wins round ” << index << “!” << endl;

             }

             else if (rightWin)

             {

                    cout << “Right wins round ” << index << “!” << endl;

             }

             else cout << “No winner for round ” << index << “.” << endl;

             cout << endl;

      }

      cout << “Left won ” << leftCount << endl << “Right won ” << rightCount << endl;

      // you need to add this line to see the output if you are running in debug mode.

      cin.get();

return 0;

}

PART B

#include <iostream>

#include <cstring>

#include <string>

#include <time.h>

using namespace std;

int main()

{

      // create three arrays of two strings–

      string sArray1[] ={“Hello, “,”Hi there, “,”What’s up, “};

      //// YOUR CODE HERE: create two more string arrays

      //// seed the random number generator

      srand(time(0));

      // Generate three sentences

      for (int i = 0; i < 3; i++)

      {

             cout << sArray1[rand()%3] << sArray2[rand()%3] << sArray3[rand()%2] << endl;

      }

      cout << endl;

      cin.get();

      return 0;

}

After you have added the additional two string arrays—sArray2 and sArray3—build and run the code. If it runs without bugs. Increase the number of strings in each array to 5 and increase the number of times the program runs by changing “i < 3” to “i < 5” in the for loop. You will also need to change the “rand()%3” to “rand()%5” in the cout statement.

PART C

#include <iostream>

#include <cstring>

#include <string>

#include <time.h>

using namespace std;

int main()

{

//Create an enumeration

enum Weapons

{

Sword, Bow, Axe, Spear, Nuclear_Weapon

};

// Create a struct

struct character

{

string name;

int health, strength, charisma;

string weapon;

float wealth;

};

// Create a struct variable

character myCharacter1;

// seed the random number generator

// Create an array of strings

srand(time(0));

// get my characters’s information

cout << “What is your character’s name? “;

getline(cin, myCharacter1.name);

cout << “What is ” << myCharacter1.name << “‘s weapon? “;

getline(cin, myCharacter1.weapon);

myCharacter1.health = rand() % 20 + 80;

myCharacter1.strength = rand() % 80 + 20;

myCharacter1.charisma = rand() % 100;

myCharacter1.wealth = float(rand() % 3000) / 100.0f;

cout << myCharacter1.name << ” has the following attributes:” << endl;

cout << “Health is ” << myCharacter1.health << endl;

cout << “Strength is ” << myCharacter1.strength << endl;

cout << “Charisma is ” << myCharacter1.charisma << endl;

cout << “Weapon is ” << weaponNames[myCharacter1.weapon] << endl; —————————————–(THIS IS THE PART THAT I CANT FIX AND I DONT UNDERSTAND WHY)

cout << “Wealth is ” << myCharacter1.wealth << endl;

cout << endl;

cin.get();

return 0;

}

Thanks!

 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"