September 10th, 2012, 05:13 PM
My buddy is in some trouble. He has to translate some coding from C# to C++, but he doesn't know how to do it. And he has to have it finished by tomorrow, which isn't enough time for him to learn how to do that. Can anyone help?
Had to split up that URL cuz I'm new
Some notes he had about it:
-takes list of product codes
-tests if modulate/10 == 0
-valid if does, else invalid
Not sure what any of that means or if its relevant at all (I don't know squat about programming, I'm just trying to be a good friend). Please help!
September 10th, 2012, 05:37 PM
September 11th, 2012, 02:14 PM
I guess it does not matter any longer, but what is all that nonsense directing us to another site using a URL you couldn't post when you could have as easily pasted teh code here directly!?
static void Main(string args)
checkCode("076281703220"); //12 numbers representing upc code
private static void checkCode(string code)
int total = 0;
for (int i = 0; i < code.Length; i++)
Console.WriteLine(code.Substring(i, 1) + " rest:" + i % 2); //test (if rest 0 multiply value by 3 if rest 1 take value(multiply by 1)
if (i % 2 == 1)
Console.WriteLine("added" + Int32.Parse(code.Substring(i, 1)));// test
total += Int32.Parse(code.Substring(i, 1)); //rest = 1 so add value
Console.WriteLine("added" + (Int32.Parse(code.Substring(i, 1)) * 3)); //test
total += (Int32.Parse(code.Substring(i, 1)) * 3); // rest = 3 so add value*3
if (total % 10 == 0) //correct UPC
Console.WriteLine("UPC IS OK");
This is very simple C# code - C# and C++ share common control-flow constructs and operators; the differences are largely at the "framework" level and in memory management and the way classes are defined and objects instantiated and destroyed. This code does not really use any of that - comprising of only a main() function and one other function. A translation really need not even have the additional function since that is the only thing main() does.
Translating this to C++ or even C is trivial; hence I guess the "Nevermind".