I'm reading up on this C++ programming excercise, and I'm really confused. Anyways, heres the program question (w/ example) in its entirety:
==============================
The greatest common divisor (GCD) of two positive integers x and y, such that x <= y, can be found by repeating the following ...
1. Let r = y % x
2. If r == 0 then the GCD is x
3. Otherwise let y = x and x = r
Rules:
* You must write both a function prototype and definition for a function named gcd, that when given two positive integers (in any order) computes (as specified above) and returns their GCD.
* You must write a main function that:
1. Prompts the user to enter three positive Integers a,b,c
2. Uses your gcd function to compute the GCD between each pair of input values, you will need to save these as well.
3. Display a reasonable report with the input values and their GCD's.
================================
Sample run(s): AKA: Screen View. AKA Answer to the questions above, what the program will look like when it runs successfully.
grid: sample10
please enter a positive integer (a) 24
please enter a positive integer (b) 8
please enter a positive integer (c) 3
Generating Report ...
gcd(24, 8) = 8
gcd(24, 3) = 3
gcd(8, 3) = 1
grid: sample10
please enter a positive integer (a) 36
please enter a positive integer (b) 20
please enter a positive integer (c) 45
Generating Report ...
gcd(36, 20) = 4
gcd(36, 45) = 9
gcd(20, 45) = 5
grid: sample10
please enter a positive integer (a) 31
please enter a positive integer (b) 19
please enter a positive integer (c) 7
Generating Report ...
gcd(31, 19) = 1
gcd(31, 7) = 1
gcd(19, 7) = 1
=======================
Now could someone PLEASE walk me through this as if I were a bloody child. This is my attempt:
=======================
#include <iostream>
using namespace std;
bool GCD(int what)
int a;
int b;
int c;
int x;
int y;
int z;
int main ()
{
r = y % x
cout << " Please Enter A positive Integer: " << endl;
cin << a;
cout << " Please Enter A positive Integer: " << endl;
cin << b;
cout << " Please Enter A positive Integer: " << endl;
cin << c;
cout << endl;
cout << " Generating Report . . . " << endl;
cout << "gcd" << "(" << a << "," << b << ")" << "=" << b << endl;
cout << "gcd" << "(" << a << "," << c << ")" << "=" << c << endl;
cout << "gcd" << "(" << b << "," << c << ")" << "=" << c << endl;
if (GCD(what))
{
????????????????????????
bool GCD(int what)
{
if r == 0
{
return x;
}
else
{
return false;
}
}
=================
Now I admit that its far from done, but I am really confused... Please if you can help, lend me a minute.
==============================
The greatest common divisor (GCD) of two positive integers x and y, such that x <= y, can be found by repeating the following ...
1. Let r = y % x
2. If r == 0 then the GCD is x
3. Otherwise let y = x and x = r
Rules:
* You must write both a function prototype and definition for a function named gcd, that when given two positive integers (in any order) computes (as specified above) and returns their GCD.
* You must write a main function that:
1. Prompts the user to enter three positive Integers a,b,c
2. Uses your gcd function to compute the GCD between each pair of input values, you will need to save these as well.
3. Display a reasonable report with the input values and their GCD's.
================================
Sample run(s): AKA: Screen View. AKA Answer to the questions above, what the program will look like when it runs successfully.
grid: sample10
please enter a positive integer (a) 24
please enter a positive integer (b) 8
please enter a positive integer (c) 3
Generating Report ...
gcd(24, 8) = 8
gcd(24, 3) = 3
gcd(8, 3) = 1
grid: sample10
please enter a positive integer (a) 36
please enter a positive integer (b) 20
please enter a positive integer (c) 45
Generating Report ...
gcd(36, 20) = 4
gcd(36, 45) = 9
gcd(20, 45) = 5
grid: sample10
please enter a positive integer (a) 31
please enter a positive integer (b) 19
please enter a positive integer (c) 7
Generating Report ...
gcd(31, 19) = 1
gcd(31, 7) = 1
gcd(19, 7) = 1
=======================
Now could someone PLEASE walk me through this as if I were a bloody child. This is my attempt:
=======================
#include <iostream>
using namespace std;
bool GCD(int what)
int a;
int b;
int c;
int x;
int y;
int z;
int main ()
{
r = y % x
cout << " Please Enter A positive Integer: " << endl;
cin << a;
cout << " Please Enter A positive Integer: " << endl;
cin << b;
cout << " Please Enter A positive Integer: " << endl;
cin << c;
cout << endl;
cout << " Generating Report . . . " << endl;
cout << "gcd" << "(" << a << "," << b << ")" << "=" << b << endl;
cout << "gcd" << "(" << a << "," << c << ")" << "=" << c << endl;
cout << "gcd" << "(" << b << "," << c << ")" << "=" << c << endl;
if (GCD(what))
{
????????????????????????
bool GCD(int what)
{
if r == 0
{
return x;
}
else
{
return false;
}
}
=================
Now I admit that its far from done, but I am really confused... Please if you can help, lend me a minute.