Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

HI, I need help constructing code program for this assignment::: IN C++ For your

ID: 667796 • Letter: H

Question

HI,

I need help constructing code program for this assignment:::

IN C++ For your assignment you are writing a number guessing game; with a twist. In your game, they are calculations where the user must guess the missing number(s). The Computer guesses a random calculation "Value1 Operator Value2 = Answer." The computer randomly displays two of the four objects. The Player must guess the remaining two objects. If the player gets one right then the computer says "one is right." The game should continue until the user has provided all the correct calculations.

For Example:

The Computer decides on 12 + 34 = 46. The computer/game then randomly displays Operator is + and Value 2 is 34. The player should now begin guessing numbers. If the player guesses 12 and 20 The computer will respond "one is right" indicating either 12 or 20 are correct.

The game stops when the player guesses 12 and 46 thus giving the random calculation 12 + 34 = 46.

So far I have........

#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <ctime>

using namespace std;

vector <int> value;

vector <char> op1;

int randomNumber;

int answer = 0;

int guess = 0;
char again;

char randomizeTheOperator(vector<char> op1);

int Performmath(vector<int> value, int answer, vector<char> op1);
void guess1(int guess, vector<int> value);
void guess2(int guess, int answer);

int _tmain(int argc, _TCHAR* argv[])
{
   do {

       op1.push_back('+');
       op1.push_back('-');
       op1.push_back('*');
       op1.push_back('/');

       srand(static_cast<unsigned int>(time(0)));
       random_shuffle(op1.begin(), op1.end());

}

Explanation / Answer

#include <iostream>
#include <ctime>
#include <sstream>
using namespace std;

int main()
{
srand((unsigned int) time (NULL)); //activates the generator
int num1 = rand()%100; //gives a random from 0 to 9
int num2 = rand()%10; //gives a random from 0 to 9
int operatorVal = rand()%4; //gives a random from 0 to 9
int result,k=0;
String firstGuess,secondGuess,object1,object2;
   int displayedIndex[2];
   int undisplayedIndex[2];
String theOperator = new String();
switch (operatorVal) {
case 0: result = num1 + num2;theOperator = "+";
break;
case 1: result = num1 - num2;theOperator = "-";
break;
case 2: result = num1 * num2;theOperator = "*";
break;
case 3: result = num1 / num2;theOperator = "/";
break;
default: cout<<"Something went wrong.";exit(0);
}
for(var i=0;i<2;i++)
{
int displayNum = rand()%4;
switch (displayNum) {
case 0: cout << num1;displayedIndex[i] = 0;
break;
case 1: cout << num2;displayedIndex[i] = 1;
break;
case 2: cout << theOperator;displayedIndex[i] = 2;
break;
case 3: cout << result;displayedIndex[i] = 3;
break;
default: cout<<"Something went wrong.";exit(0);
}
}
   for(i=0;i<4;i++)
       {
       if( (i != displayedIndex[0]) && (i != displayedIndex[1]))
           undisplayedIndex[k] = i;
           k++;
       }
   switch (undisplayedIndex[0]) {
       case 0: object1 = static_cast<ostringstream*>( &(ostringstream() << num1) )->str();
               break;
       case 1: object1 = theOperator;
break;
case 2: object1 = static_cast<ostringstream*>( &(ostringstream() << num2) )->str();
break;
case 3: object1 = static_cast<ostringstream*>( &(ostringstream() << result) )->str();
break;
default: cout<<"Something went wrong.";exit(0);
  
   }
   switch (undisplayedIndex[1]) {
       case 0: object2 = static_cast<ostringstream*>( &(ostringstream() << num1) )->str();
               break;
       case 1: object2 = theOperator;
break;
case 2: object2 = static_cast<ostringstream*>( &(ostringstream() << num2) )->str();
break;
case 3: object2 = static_cast<ostringstream*>( &(ostringstream() << result) )->str();
break;
default: cout<<"Something went wrong.";exit(0);
   }
  
for(;;)
{
cout << "First guess";
cin >> firstGuess;
cout << "Second guess";
cin >> secondGuess;
if (object1 != object2)
       {
       if ( ((firstGuess == object1) || (firstGuess == object2)) || ((secondGuess == object1) || (secondGuess == object2)) && (firstGuess != secondGuess) )
               {
               cout << "Correct guesses";
               exit(0);
               }
           else if ( ((firstGuess == object1) || (firstGuess == object2)) || ((secondGuess == object1) || (secondGuess == object2)) && (firstGuess == secondGuess) )
               {
               cout << "One is right";
               }
       }
   else if ( object1 == object2 )
       {
           if ( ((firstGuess == object1) || (firstGuess == object2)) || ((secondGuess == object1) || (secondGuess == object2)) && (firstGuess != secondGuess) )
               {
               cout << "One is right";
               }
           else if ( ((firstGuess == object1) || (firstGuess == object2)) || ((secondGuess == object1) || (secondGuess == object2)) && (firstGuess == secondGuess) )
               {
               cout << "Correct guesses";
               exit(0);
               }
       }
}
return 0;
}