code not working

Gura_Kid's Avatar, Join Date: Feb 2009
Newbie Member
I'm trying to solve TOO + TOO + TOO + TOO = GOOD using a c++ program.

My solution to this, is to use a nested loop for each unique letter (in this case T, O, G, D). The loops would systematically assign the digits from 0-9 to each letter.

However the following program gives me the wrong results


Code:
#include <iostream>
using namespace std;

int main() {
   int T, O, G, D;
   for (T=0;T<=9;T++) {
      for (O=0;O<=9;O++) {
         for (G=0;G<=9;G++) {
            for (D=0;D<=9;D++) {
               if ( (T*100 + O*10 + O) * 4 == (G*1000)+(O*100)+(O*10)+D) {
                  cout << "T=" << T << "\nO=" << O << "\nG=" << G << "\nD=" << D << endl;
               }
            }
         }
      }
   }
   cout << "Press <ENTER> to exit. ";
   cin.get();
   return 0;
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
How are the results wrong?
What results did you get, and what results did you expect?
Is a requirement that T,O,G,D are all unique? If so, then you haven't coded this into your program.
Is a requirement that neither of TOO and GOOD begin with zero? Similarly you haven't coded that in.