Page 1 of 1

Ben Goes back to C++

PostPosted: 10 Oct 2016, 16:16
by Ben
Before I make an account on a more appropriate forum, I figure I'll try my luck here (besides, I've found that forums are generally hostile towards new members with beginner questions...)

Anyway, I am making a simple program that uses Euclidian method for finding the GCD. Very simple, but I can't get my program to comile. It's a simple error, but my c skills are a bit rusty.
  Code:
#include <iostream> using namespace std; double greatestCommonDivisor(double first, double second); int main () { //variables double first, second; do { cout << "Welcome to Euclid's method for finding the GCD." << endl << "To quit, enter 0 for either number." << endl; cout << "Enter the fist number:"; cin >> first; cout << "Enter the second number:"; cin >> second; greatestCommonDivisor(first, second); } while (first != 0 && second != 0); return 0; } double greatestCommonDivisor(first, second) { if(second == 0) return first; return greatestCommonDivisor(second, first % second); }
I get the error:
gcdc.cpp: In function `int main()':
gcdc.cpp:30: error: expected `;' before '{' token

seems like a missing semicolen, but I don't see it.

Thanks guys.

Re: Ben Goes back to C++

PostPosted: 10 Oct 2016, 17:32
by Krom
Not sure. You need to check in the IDE what makes the compiler happy.

Mine complains only about mixed input arguments for greatestCommonDivisor (declared double, but "first % second" appears to require int?). And refuses to build due to "LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt"

Re: Ben Goes back to C++

PostPosted: 10 Oct 2016, 18:46
by Ben
I had the int to double error before. I was able to fix it on my end though. Strange it persists for you.

Re: Ben Goes back to C++

PostPosted: 10 Oct 2016, 22:30
by Ben
LOL seems I needed only to take a break for a few hours. The problem was obvious: was missing parenthesis around 0 on return (0); :)

Now I have more syntax errors. grrr

Re: Ben Goes back to C++

PostPosted: 11 Oct 2016, 04:10
by Krom
Good luck! )

Re: Ben Goes back to C++

PostPosted: 25 Oct 2016, 10:12
by zombie01
Ah C++, the language of love.