Can't get program to work. Beginnner.

#include <iostream>
#include <cmath>
#include <cstdlib>

using namespace std;

void GCD();
void fact();
void fib();
void prop();
void dio();



void GCD()
{
int m,n,r;
cout << "The purpose of this to find the greatest common factor of two intergers.";
cout << "m= ";
cin >> m;
cout << "n= ";
cin >> n;
r = m % n;

while (r!=0)
{
m = n;
n = r;
r = m % n;
}
cout << "The answer is: " << n << endl;
}

void fact()
{
double long prod;
prod = 1;
cout << "0! = ";
cout << "i = ";
0! = 1;

for (int i=2; i<50; i++);
{
prod = prod * i;
cout << i << "!_=_" << prod << endl;
}
}

void fib()
{
long fn, f1, f2;
f1 = f2 = 1;
for (int i=3; i<50; i++)
cout << f1 << endl;
cout << f2 << endl;
fn = f1 + f2;
cout << i << " " << fn << endl;
f1 = f2;
f2 = fn;
}

void prop()
{
d = {0,1,2,3,4,5,6,7,8.9}
for (int A = 1; A<=9;A++)
for (int B = 0; B<=9,B++)
for (int C = 0; C <=9,C++)
for (int D = 0; D<=9,D++)
{
if pow (A,B)* pow (C,D)
1000 * A + 100 * B + 10 * C + D;
cout << A<<B<<C<<D
}

void dio()
{
d = {0,1,2,3,4,5,6,7,8,9}
for (int w = 1; w<=9;w++)
for (int x = 0; x<=9,x++)
for (int y = 0; y <=9,y++)
for (int z = 0; z<=9,z++)
if pow (w,3) + pow (x,3) + pow (y,3) = pow(z,3)
w * 3 + x * 3 + y * 3 = z * 3
cout << w<<x<<y<<=z


}

int main ()
{
int choice;

cout << "Please enter a menu choice.\n\n";
cout << "1) Computer the GCD of 2 integers.\n";
cout << "2) Output n!.\n";
cout << "3) Output Fibonacci numbers.\n";
cout << "4) Find the four positive digits.\n";
cout << "5) Use the Diophantine equation.\n";
cout << "6) Quit.\n\n";
cout << "Choice: ";
cin >> choice;

while (choice!= 6)
{
switch (choice)
{ case 1: void GCD(); break;
case 2: void fact(); break;
case 3: void fib(); break;
case 4: void prop(); break;
case 5: void dio(); break;
case 6: exit; break;
default: cout << "Not an option. Try again.\n";
}
cout << "Choice:"" ";
cin >> choice;
}
return 0;
}
Not sure what errors it gives you or what happens, but to call a function, you don't specify return type. In this case, you'll want to leave out "void" in each of your switch cases.

Also, to exit the program in case 6, you just need "break;". Then to make sure that the cout and cin statements aren't executed, you'll want to move those two to the top of your while loop. That means you'll want to remove the cout and cin statements from before the loop, and you'll need to set a value at the declaration of "choice" so that it can have something to compare it to at the beginning of the while loop.

In addition, you can do "exit();" as a function, and it'll just end your program.

Finally, you have two extra quotes in the last cout statement, so you'll want to remove the middle two. If you want them to stay appearing though, then add the backslash before each of the double quotes, and it'll let them be displayed.

Two other tips for you... You can display all your code in [/code] tags, and it'll format it correctly. And second, for multiple cout statements, if you remove the semi colon at the end of one line, you won't need to rewrite the "cout" part on the second line (because the compiler reads from beginning to end, and will see that as one line).

Anyways, your main() function would look like this...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
int main ()
{
int choice=0;

cout << "Please enter a menu choice.\n\n"
<< "1) Computer the GCD of 2 integers.\n"
<< "2) Output n!.\n"
<< "3) Output Fibonacci numbers.\n"
<< "4) Find the four positive digits.\n"
<< "5) Use the Diophantine equation.\n"
<< "6) Quit.\n\n";

while (choice!= 6)
{
cout << "Choice: ";
cin >> choice;
switch (choice)
{ case 1: GCD(); break;
case 2: fact(); break;
case 3: fib(); break;
case 4: prop(); break;
case 5: dio(); break;
case 6: break;
default: cout << "Not an option. Try again.\n";
}
}
return 0;
}
Topic archived. No new replies allowed.