Coding Help (Euclidean Division)

I literally don't understand anything about coding in C++ (I'm new to coding in general, and my professor unfortunately isn't very helpful.) Apparently I'm supposed to create a code in C++ to find the GCD of 318 and 294 using the following psuedocode (literally don't even know what a psuedocode really is):

function gcd (a, b)
while b != 0
t := b
b := a mod b
a := t
return a

What code would I use in C++ for this? Or can somebody explain it to me better so that I can figure out the code?
This one is easier and you should probably work on it before the sort.

pseudo code is "fake code" that is used to show what the real code might look like, but the syntax and so on are not legal for the language.

int gcd(int a, int b)  //this is a "function" ... like in math, y = f(x) type function, literally here. 
// the syntax is type functioname(parameters) 
{ //begin and end of blocks use {} braces.
    int t = b;  //:= is pascal  for assignment which is = in c 
//note that we put a type on things we create, int = integer ...
    while(b) //in c, that which is not zero is true. 
          t = b; 
          b = a%b; // % is mod
          a = t;
     return a;

This is identical to what you had with c++ syntax. I did it for you because you have to start somewhere, but you need to understand this very well if you want to be able to do the other one.
Last edited on
Registered users can post here. Sign in or register to post.