smiles are caused
add space or... don't rememberCode::D
code-tags can help also
smiles are caused
add space or... don't rememberCode::D
code-tags can help also
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
simplify2(x,GCD(w, x)) << endl;
fuction int simplify2 - missing closing } in the function body
Last edited by vart; 12-13-2006 at 11:49 AM.
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
I fixed thboth of those but I still get errors.
Code:Info :Compiling C:\DOCUMENTS AND SETTINGS\LABPC\DESKTOP\fraction hoskins beta v2.cpp Error: fraction hoskins beta v2.cpp(39,5):Declaration syntax error Error: fraction hoskins beta v2.cpp(40,8):Declaration terminated incorrectly Error: fraction hoskins beta v2.cpp(47,3):Unexpected }
Cool, no smilys.
could you fix your indentetion and post a last code
also pointing the lines containing errors (with comments) will help
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
Here is the new code.
and here are the errorsCode:#include <iostream.h> int GCD(int a, int b ) { int remainder, quotient, divisor, numerator; if (a > b) { remainder=a%b; quotient=a/b; divisor=b; } else { remainder=b%a; quotient=b/a;divisor=a; } } while( remainder!=0 ) //error 1 { numerator=divisor; divisor=quotient; remainder=numerator%divisor; quotient=numerator/divisor; } return divisor; } //error2 int simplify1(int a, int GCD ) { int product1; { do { product1=a / GCD; } while ( a!=0); } return product1; } int simplify2(int b, int GCD ) int product2; //error3 { //error4 do { product2=b / GCD; } while ( b!=0 ); } return product2; } //error5 int main() { int w, x; char junk; cout << "This program allows calculating the GCD\n"; cout << "Value of first numerator: "; cin >> w; cout << "Value of first denominator: "; cin >> x; cout << "\nThe Greatest Common Divisor of " << w << " and " << x << " is " << GCD(w, x) << endl; cout << "\nThe simplified fraction is " << w << " and " << x << simplify1(w,GCD(w, x)) << " and "<< simplify2(x,GCD(w, x)) << endl; cin >> junk; //This input allows for display. return 0; }
Code:Info :Compiling C:\Documents and Settings\labpc\Desktop\fraction hoskins beta v2.cpp Warn : fraction hoskins beta v2.cpp(16,2):Function should return a value Warn : fraction hoskins beta v2.cpp(16,2):'numerator' is declared but never used Warn : fraction hoskins beta v2.cpp(16,2):'divisor' is assigned a value that is never used Warn : fraction hoskins beta v2.cpp(16,2):'quotient' is assigned a value that is never used Warn : fraction hoskins beta v2.cpp(16,2):'remainder' is assigned a value that is never used Error: fraction hoskins beta v2.cpp(18,8):Declaration terminated incorrectly Error: fraction hoskins beta v2.cpp(27,2):Unexpected } Error: fraction hoskins beta v2.cpp(44,5):Declaration syntax error Error: fraction hoskins beta v2.cpp(45,8):Declaration terminated incorrectly Error: fraction hoskins beta v2.cpp(54,3):Unexpected }
wow, my indentation really does suck. sorry.
you have to many closing } in the GCD function
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
this is the new code.
and here is the errorsCode:#include <iostream.h> int GCD(int a, int b ) { int remainder, quotient, divisor, numerator; if (a > b) { remainder=a%b; quotient=a/b; divisor=b; } else { remainder=b%a; quotient=b/a;divisor=a; } while( remainder!=0 ) { numerator=divisor; divisor=quotient; remainder=numerator%divisor; quotient=numerator/divisor; } return divisor; } int simplify1(int a, int GCD ) { int product1; { do { product1=a / GCD; } while ( a!=0); } return product1; } int simplify2(int b, int GCD ) int product2; // error 1 { // error 2 do { product2=b / GCD; } while ( b!=0 ); } return product2; int main() { int w, x; char junk; cout << "This program allows calculating the GCD\n"; cout << "Value of first numerator: "; cin >> w; cout << "Value of first denominator: "; cin >> x; cout << "\nThe Greatest Common Divisor of " << w << " and " << x << " is " << GCD(w, x) << endl; cout << "\nThe simplified fraction is " << w << " and " << x << simplify1(w,GCD(w, x)) << " and "<< simplify2(x,GCD(w, x)) << endl; cin >> junk; //This input allows for display. return 0; }
Code:Info :Compiling C:\Documents and Settings\labpc\Desktop\fraction hoskins beta v2.cpp Error: fraction hoskins beta v2.cpp(44,5):Declaration syntax error Error: fraction hoskins beta v2.cpp(45,8):Declaration terminated incorrectly
Code:int simplify2(int b, int GCD ) { int product2; // error 1 { // error 2 do { product2=b / GCD; } while ( b!=0 ); } return product2; }
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
Alright, I fixed that.
I got an email from the teacher. He wants us to add two fractions together and simplify now. if he keeps adding stuff to our assignments we will never get it done.
Code:#include <iostream.h> int GCD(int a, int b ) { int remainder, quotient, divisor, numerator; if (a > b) { remainder=a%b; quotient=a/b; divisor=b; } else { remainder=b%a; quotient=b/a;divisor=a; } while( remainder!=0 ) { numerator=divisor; divisor=quotient; remainder=numerator%divisor; quotient=numerator/divisor; } return divisor; } int simplify(int a, int GCD ) { int product; { //do { product=a / GCD; } //while ( a!=0); } return product; } /* int simplify1(int a, int GCD ) { int product1; { do { product1=a / GCD; } while ( a!=0); } return product1; } int simplify2(int b, int GCD ) { int product2; // error 1 // error 2 do { product2=b / GCD; } while ( b!=0 ); return product2; } */ int main() { int w, x,y,z; char junk; cout << "This program allows calculating the GCD\n"; cout << "Value of first numerator: "; cin >> w; cout << "Value of first denominator: "; cin >> x; cout << "Value of second numerator: "; cin >> y; cout << "Value of second denominator: "; cin >> z; cout << "\nThe Greatest Common Divisor of " << w << " and " << x << " is " << GCD(w, x) << endl; cout << "\nThe simplified fraction is " << w << " and " << x << simplify(w,GCD(w, x)) << " and "<< simplify(x,GCD(w, x)) << endl; cin >> junk; //This input allows for display. return 0; }
a is not changed inside the loopCode:do { product1=a / GCD; } while ( a!=0);
so if the condition was true in the beginning - it will be true ever
so the loop will be endless
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
here is the new code
Code:#include <iostream.h> int GCD(int a, int b ) { int remainder, quotient, divisor, numerator; if (a > b) { remainder=a%b; quotient=a/b; divisor=b; } else { remainder=b%a; quotient=b/a;divisor=a; } while( remainder!=0 ) { numerator=divisor; divisor=quotient; remainder=numerator%divisor; quotient=numerator/divisor; } return divisor; } int simplify(int a, int GCD ) { int product; { { product=a / GCD; } } return product; } int main() { int w, x,y,z; char junk; cout << "This program allows calculating the GCD\n"; cout << "Value of first numerator: "; cin >> w; cout << "Value of first denominator: "; cin >> x; cout << "Value of second numerator: "; cin >> y; cout << "Value of second denominator: "; cin >> z; cout << "\nThe Greatest Common Divisor of " << w << " and " << x << " is " << GCD(w, x) << endl; cout << "\nThe simplified fraction of " << w << " and " << x << " is " << simplify(w,GCD(w, x)) << " and "<< simplify(x,GCD(w, x)) << endl; cin >> junk; //This input allows for display. return 0; }
is it working?
seems to be ok, except the indentation and to many unnecacery breckets...
also GCD(w,x) is calculated 3 times - you can calculate it once and store in the temporary varyable.
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler