My triple x code

I decided to challenge myself by tackling this project on my own. I’m new to c++, so any feedback is greatly appreciated.

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

void PlayGameWithDifficulty(int difficulty)
{
srand(time(NULL));
int a = rand() % difficulty + difficulty;
int b = rand() % difficulty + difficulty;
int c = rand() % difficulty + difficulty;

int sum = a + b + c;
int product = a * b * c;

int currentProduct = 0, currentSum = 0;

do
{
cout << "Level " << difficulty << endl;
cout << endl;

  int num1 = 0, num2 = 0, num3 = 0;

  cout << "The serum contains three chemicals at various quantities" << endl;
  cout << "The volume of each vial when multiply has a product of " << product << endl;
  cout << "The volume of each vial when added has a sum of " << sum << endl;
  cout << endl;

  cout << "Enter the volume of each vial (3 total):" << endl;
  cin >> num1 >> num2 >> num3;

  currentProduct = num1 * num2 * num3;
  currentSum = num1 + num2 + num3;
  
  cout << endl;
  if (product == currentProduct && sum == currentSum)
  {
  	cout << "===================================================================" << endl;
  	cout << "Congrats doctor, you have cured the patient but more need your help" << endl;
  	cout << "===================================================================" << endl;
  }
  else
  {
  	cout << "=======================================================" << endl;
  	cout << "The patient lost their life, doctor. You have failed us" << endl;
  	cout << "=======================================================" << endl;
  }
  	
  cout << endl;

} while (product != currentProduct && sum != currentSum);
}

int main()
{
int difficulty = 2;
int maxDifficulty = 10;

while (difficulty <= maxDifficulty)
{
PlayGameWithDifficulty(difficulty);
++difficulty;
}

cout << endl;
cout << “Congratulation doctor, you have cured the outbreak” << endl;

return 0;
}

Privacy & Terms