32.8k views
3 votes
C++ what is wrong with my equation?

int AnswerNum = (((OriginalNum * 2) * 100) + OriginalNum);
cout << " Your Answer was: ";
cout << AnswerNum;

Probably not the best way to do this but it is the way i know how, which is apparently not the way to do it at all.

C++ what is wrong with my equation? int AnswerNum = (((OriginalNum * 2) * 100) + OriginalNum-example-1
User Ramnath
by
5.8k points

1 Answer

3 votes

This (simplified) piece of code seems to work:

int OriginalNum;

int AnswerNum;

cout << "Insert your number: ";

cin >> OriginalNum;

AnswerNum = 201*OriginalNum;

cout << "The answer is:";

cout << AnswerNum;

If I copy what visible in your screen, the compiler complains about the variable OriginalNum not being declared. Try to paste my code and see if you have any issue.

Note: the expression OriginalNum*2*100 + OriginalNum is simply a multiplication by 201!

In fact, you have


x\mapsto 2x \mapsto 2x\cdot 100 = 200x \mapsto 200x+x = 201x

User Xavier
by
6.6k points