Just a simple C++ question

in the section TripleX, there is a part that I am sooo curious about.

From Line 29 to Line 31, I added the cout for all the answer because I want to test the game’s winning part by knowing the answer immediately and type the answers to test the game.

But the problem is… when I play it, it doesn’t print them out, instead, the game runs normally but the “Cheat” doesn’t work.

I really wonder why, as the AnsSum and the AnsProduct can be printed out perfectly fine, why the “Cheat” cannot be printed out?
TripleX cout question.zip (1.0 KB)

Your code doesn’t compile, so I assume you’re running an old build.

Also may I ask why you’re using C++/CLI instead of just normal C++?


Code questions:

  1. Why is everything in Game a double?
  2. Is returning a double for Game correct?
  3. Why use global variables?
  4. Are you aware you have created 4 different EndLevelBool variables? i.e. none of them are the same object.

Idk what is the differences between CLI and normal C++, I am using Visual Studio 2019 and I am using the default settings…

I used double Game because I wanted to tell the value of the AnsA, AnsB and AnsC to other functions but I dont know how.

4 different EndLevelBool variables?

Sorry, I wanted to give myself a bit more challenge so I started the project after watching the tutorial from start to finish to test my memory.

C++/CLI is Microsoft’s thing. When you create a project you want this one and not the one with “CLR”

double is a floating point type which is used to express any real number. Since we’re only interested in whole numbers this isn’t the correct type to be using. int should be used instead.

//1
using namespace System;
bool EndLevelBool;
int Level = 1;
//...

//2
std::cout << "You entered the CORRECT answer!\n";
bool EndLevelBool = true;
//...

//3
std::cout << "AnsC: " << AnsC << std::endl;
bool EndLevelBool = false;
//...

//4
std::cin.ignore();
bool EndLevelBool = Game(Level);

It’s good that you’re doing things on your own but perhaps this is the wrong way to go about it? It seems like you’re trying hard to memorize code rather than to understand how it works.

Instead of trying to recreate TripleX from memory. Try create something else entirely, like a number guesser. Ask the user to think of a number and then have the game come up with a number and ask the user if it’s higher, lower, or the correct number.

yes, I know how to do that, i am trying to implement a timer into it, to require players to finish the level in a specific time according to levels.

I suggested that because it doesn’t like you quite understand how everything works as you have multiple beginner level errors in the code you posted as mentioned above.

Do you understand my explanations of such and how to solve them?

ok i understand, it works now, thx!

I solved the problems now, and I am trying to implement a timer into it

Then you should take a look at std::chrono
https://en.cppreference.com/w/cpp/chrono

Specifically steady_clock. Example:

#include <chrono>
#include <iostream>
namespace chrono = std::chrono;

int main()
{
	auto t1 = chrono::steady_clock::now();
	std::cin.ignore();
	auto t2 = chrono::steady_clock::now();
	auto duration = chrono::duration_cast<chrono::seconds>(t2 - t1);
	std::cout << duration.count() << std::endl;
}
1 Like

Privacy & Terms