Hello all. I am new to the board and hope to build great relationships with other forum members. I am working on a program for class that is supposed to show the GCD. I used a text editor to make it, but when i put it in Visual express 2008, it keeps showing error messages, when I thought I did it properly. Can anyone show me what I did wrong so I can make it work in visual? Thank you very much

/*******************************************************/
/*  File: name of your file with the source code       */
/*                                                     */
/* Created by: give your  name                         */
/* Date: give the date                                 */
/*                                                     */
/* Program to compute the GCD of two integers          */
/*                                                     */
/* Inputs: (keyboard)                                  */
/* 1. Two numbers - only positive numbers allowed       */
/*                                                     */
/* Output:                                             */
/* Print the GCD of given numbers on the screen        */
/*                                                     */
/* Algorithm: Euclid's Algorithm                       */
/*                                                     */
/*******************************************************/


#include "stdafx.h"
#include <iostream>


using namespace std ;


int main()
{


Declare x, y, temp, remainder as Integer.
int x;
int y;
int temp
int remainder = 1;


// read in the two integers


cout << endl ;
cout << "Enter the first number (positive integer) : " ;
cin >> x ;
cout << "Enter the second number (positive integer) : " ;
cin >> y ;


//echo inputs


cout << "Input numbers are: " << x << " , " << y << endl ;


Write a C++ if statement to determine if x < y.


if ((x == 0) || (y == 0))
{
cout << "ERROR:  Value of 0 has been entered."
return (-1);
}


if (x < y)
{ // exchange values of x and y
temp = x;
x = y;
y = temp;
}


/* At this point we will always have x >= y */



Initialize remainder.


while ( remainder != 0  )
{
Write the loop expression and loop body code in C++.
In C++, the expression (x % y) gives the remainder
after dividing x by y.


// value of q
temp = x / y;


// value of r
remainder = x % y;


// replace x with y
x = y;


// replace y with remainder
y = remainder;


}


// display the result
cout << endl ;
cout << "The GCD is: " << y << endl ;


return (0); // terminate with success
}

Please use code tags when you post code.

Mostly you have there comments not marked as comments, and also a couple of semicolons were missing ...
Use the VC++ editor to edit code, so you'll benefit from its syntax colouring, effectively meaning less errors.

#include "stdafx.h"
#include <iostream>

using namespace std ;

int main()
{

// Declare x, y, temp, remainder as Integer.
int x;
int y;
int temp ;
int remainder = 1;

// read in the two integers

cout << endl ;
cout << "Enter the first number (positive integer) : " ;
cin >> x ;
cout << "Enter the second number (positive integer) : " ;
cin >> y ;

//echo inputs

cout << "Input numbers are: " << x << " , " << y << endl ;

// Write a C++ if statement to determine if x < y.

if ((x == 0) || (y == 0))
{
cout << "ERROR: Value of 0 has been entered." ;
return (-1);
}

if (x < y)
{ // exchange values of x and y
temp = x;
x = y;
y = temp;
}

/* At this point we will always have x >= y */


// Initialize remainder.

while ( remainder != 0 )
{

/*
Write the loop expression and loop body code in C++.
In C++, the expression (x % y) gives the remainder
after dividing x by y.
*/

// value of q
temp = x / y;

// value of r
remainder = x % y;

// replace x with y
x = y;

// replace y with remainder
y = remainder;

}

// display the result
cout << endl ;
cout << "The GCD is: " << y << endl ;

return (0); // terminate with success
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.