Ok im kinda new to C++
How can i increment a string by adding an integer value onto the end?
i am converting a decimal number to binary using the remainder method
in other words divide x by 2 and modulate x by two so im grabbing the remainder each time
12 in binary is 1100
wen i run the program if i include "cout << modx" in the loop i get a result of
0011
which is the reverse of what i need.
when i implemented this in VB6 i was able to have a string a increment it by addding the result of the MOD onto the end. Then after that i was able to reverse the string using another algorithm
Here is my code using C++
People on other forums have been getting confused about what i am trying to achieve. So i have implented this in VB6Code:#include <iostream> #include <string> using namespace std; int main (){ int x; int modx; string Reslt; cout << "Enter a Decimal"; cin >> x; while (x > 0){ modx = x % 2; Reslt = Reslt + modx; <----- This is my problem area x = x / 2; } cout << Reslt return 0; }
VB6 snippit
and my result will then be kCode:Do Until x = 0 intMod = x Mod 2 Result = Result & intMod x = x / 2 x = x - 0.49 x = CLng(x) Loop and i could then reverse the string y = Len(Result) Do Until y = 0 Rev = Mid(Result, y, 1) k = k + Rev y = y - 1 Loop