Map Database  •  FAQ  •  RSS  •  Login

Ben Goes back to C++

<<

Ben

User avatar

Former Site Admin

Posts: 3814

Joined: 08 Jan 2009, 23:00

Location: California - Pacific Time (UTC -8/-7 Summer Time)

Post 10 Oct 2016, 16:16

Ben Goes back to C++

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.
You do not have the required permissions to view the files attached to this post.
I used to spam this forum so much...
<<

Krom

User avatar

Knights Province Developer

Posts: 3280

Joined: 09 May 2006, 22:00

KaM Skill Level: Fair

Location: Russia

Post 10 Oct 2016, 17:32

Re: Ben Goes back to C++

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"
Knights Province at: http://www.knightsprovince.com
KaM Remake at: http://www.kamremake.com
Original MBWR/WR2/AFC/FVR tools at: http://krom.reveur.de
<<

Ben

User avatar

Former Site Admin

Posts: 3814

Joined: 08 Jan 2009, 23:00

Location: California - Pacific Time (UTC -8/-7 Summer Time)

Post 10 Oct 2016, 18:46

Re: Ben Goes back to C++

I had the int to double error before. I was able to fix it on my end though. Strange it persists for you.
I used to spam this forum so much...
<<

Ben

User avatar

Former Site Admin

Posts: 3814

Joined: 08 Jan 2009, 23:00

Location: California - Pacific Time (UTC -8/-7 Summer Time)

Post 10 Oct 2016, 22:30

Re: Ben Goes back to C++

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
I used to spam this forum so much...
<<

Krom

User avatar

Knights Province Developer

Posts: 3280

Joined: 09 May 2006, 22:00

KaM Skill Level: Fair

Location: Russia

Post 11 Oct 2016, 04:10

Re: Ben Goes back to C++

Good luck! )
Knights Province at: http://www.knightsprovince.com
KaM Remake at: http://www.kamremake.com
Original MBWR/WR2/AFC/FVR tools at: http://krom.reveur.de
<<

zombie01

User avatar

Pikeman

Posts: 152

Joined: 21 Jul 2014, 13:04

KaM Skill Level: Fair

Post 25 Oct 2016, 10:12

Re: Ben Goes back to C++

Ah C++, the language of love.

Return to “Computers & Technology”

Who is online

Users browsing this forum: No registered users and 3 guests