Hi
The following code is incomplete.
1: I'm getting this error: undefined reference to `swapthree(float&, float&, float&)'| . I have been unable to understand the reason for this error and don't know what to fix. Please help me
2: Could you please tell me some general thumb rule to know how many if's, else if's I would need in such situation? Thanks.
Code:// swap3numbers.cpp // swap three number so that they appear in descending order // it is assumed entered numbers are distinct #include <iostream> #include <cstdlib> using namespace std; int swapthree(float& dummya, float& dummyb, float& dummyc); int main() { float a, b, c; cout << "enter a: "; cin >> a; cout << "enter b: "; cin >> b; cout << "enter c: "; cin >> c; if ( swapthree(a, b, c) ) { cout << "the entered numbers in descending order: " << a << " " << b << " " << c << endl; } else { cout << "some error\n"; } system("pause"); return 0; } //----------------------------------------------------------------- // swapthree() definition int swapthree(float& dummya, float dummyb, float dummyc) { if (dummya > dummyb > dummyc) { return 1; } else if (dummya > dummyb && dummyb < dummyc) { float temp = dummyb; dummyb = dummyc; dummyc = temp; return 1; } else if (dummyb > dummya > dummyc) { float temp = dummya; dummya = dummyb; dummyb = temp; return 1; } }



LinkBack URL
About LinkBacks



