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 :crazy: Code: [COLOR=#008200]#include <iostream>[/COLOR] [B][COLOR=#006699]using[/COLOR][/B] [B][COLOR=#006699]namespace[/COLOR][/B] std[COLOR=#999900];[/COLOR] [B][COLOR=#006699]int[/COLOR][/B] main[COLOR=#999900]()[/COLOR] [COLOR=#999900]{[/COLOR] [B][COLOR=#006699]int[/COLOR][/B] T[COLOR=#999900],[/COLOR] O[COLOR=#999900],[/COLOR] G[COLOR=#999900],[/COLOR] D[COLOR=#999900];[/COLOR] [B][COLOR=#006699]for[/COLOR][/B] [COLOR=#999900]([/COLOR]T[COLOR=#999900]=[/COLOR][COLOR=#006666]0[/COLOR][COLOR=#999900];[/COLOR]T[COLOR=#999900]<=[/COLOR][COLOR=#006666]9[/COLOR][COLOR=#999900];[/COLOR]T[COLOR=#999900]++)[/COLOR] [COLOR=#999900]{[/COLOR] [B][COLOR=#006699]for[/COLOR][/B] [COLOR=#999900]([/COLOR]O[COLOR=#999900]=[/COLOR][COLOR=#006666]0[/COLOR][COLOR=#999900];[/COLOR]O[COLOR=#999900]<=[/COLOR][COLOR=#006666]9[/COLOR][COLOR=#999900];[/COLOR]O[COLOR=#999900]++)[/COLOR] [COLOR=#999900]{[/COLOR] [B][COLOR=#006699]for[/COLOR][/B] [COLOR=#999900]([/COLOR]G[COLOR=#999900]=[/COLOR][COLOR=#006666]0[/COLOR][COLOR=#999900];[/COLOR]G[COLOR=#999900]<=[/COLOR][COLOR=#006666]9[/COLOR][COLOR=#999900];[/COLOR]G[COLOR=#999900]++)[/COLOR] [COLOR=#999900]{[/COLOR] [B][COLOR=#006699]for[/COLOR][/B] [COLOR=#999900]([/COLOR]D[COLOR=#999900]=[/COLOR][COLOR=#006666]0[/COLOR][COLOR=#999900];[/COLOR]D[COLOR=#999900]<=[/COLOR][COLOR=#006666]9[/COLOR][COLOR=#999900];[/COLOR]D[COLOR=#999900]++)[/COLOR] [COLOR=#999900]{[/COLOR] [B][COLOR=#006699]if[/COLOR][/B] [COLOR=#999900]([/COLOR] [COLOR=#999900]([/COLOR]T[COLOR=#999900]*[/COLOR][COLOR=#006666]100[/COLOR] [COLOR=#999900]+[/COLOR] O[COLOR=#999900]*[/COLOR][COLOR=#006666]10[/COLOR] [COLOR=#999900]+[/COLOR] O[COLOR=#999900])[/COLOR] [COLOR=#999900]*[/COLOR] [COLOR=#006666]4[/COLOR] [COLOR=#999900]==[/COLOR] [COLOR=#999900]([/COLOR]G[COLOR=#999900]*[/COLOR][COLOR=#006666]1000[/COLOR][COLOR=#999900])+([/COLOR]O[COLOR=#999900]*[/COLOR][COLOR=#006666]100[/COLOR][COLOR=#999900])+([/COLOR]O[COLOR=#999900]*[/COLOR][COLOR=#006666]10[/COLOR][COLOR=#999900])+[/COLOR]D[COLOR=#999900])[/COLOR] [COLOR=#999900]{[/COLOR] cout [COLOR=#999900]<<[/COLOR] [COLOR=#646464]"T="[/COLOR] [COLOR=#999900]<<[/COLOR] T [COLOR=#999900]<<[/COLOR] [COLOR=#646464]"\nO="[/COLOR] [COLOR=#999900]<<[/COLOR] O [COLOR=#999900]<<[/COLOR] [COLOR=#646464]"\nG="[/COLOR] [COLOR=#999900]<<[/COLOR] G [COLOR=#999900]<<[/COLOR] [COLOR=#646464]"\nD="[/COLOR] [COLOR=#999900]<<[/COLOR] D [COLOR=#999900]<<[/COLOR] endl[COLOR=#999900];[/COLOR] [COLOR=#999900]}[/COLOR] [COLOR=#999900]}[/COLOR] [COLOR=#999900]}[/COLOR] [COLOR=#999900]}[/COLOR] [COLOR=#999900]}[/COLOR] cout [COLOR=#999900]<<[/COLOR] [COLOR=#646464]"Press <ENTER> to exit. "[/COLOR][COLOR=#999900];[/COLOR] cin[COLOR=#999900].[/COLOR][B][COLOR=#006699]get[/COLOR][/B][COLOR=#999900]();[/COLOR] [B][COLOR=#006699]return[/COLOR][/B] [COLOR=#006666]0[/COLOR][COLOR=#999900];[/COLOR]
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.