![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Programming A discussion forum for programs and programming used in tech-related businesses. |
![]() |
|
|
Thread Tools |
|
|
#1 (permalink) |
|
Registered User
Join Date: May 2008
Posts: 1
OS: vista
|
I can't figure out what is wrong with my C++ code
Program Description: This program reads in the lengths of
a four sided object, determines whether it is a square or rectangle and its perimeter and outputs all that info. #include <iostream> using namespace std; void GetData(float &fSide1, float &fSide2, float &fSide3, float &fSide4); bool TooSmall(float fSide1,float fSide2,float fSide3,float fSide4); float Perimeter(float fSide1,float fSide2, float fSide3,float fSide4); bool isSquare(float fSide1,float fSide2,float fSide3,float fSide4); bool isRect(float fSide1,float fSide2,float fSide3,float fSide4); void Print(float fSide1,float fSide2,float fSide3,float fSide4,float fPeri,bool bSquare,bool bRect); int main() { char cAgain; float fSide1, fSide2, fSide3, fSide4, fPeri; bool bSquare, bRect; do { GetData(fSide1, fSide2, fSide3, fSide4); fPeri = Perimeter(fSide1, fSide2, fSide3, fSide4); bSquare = Square(fSide1, fSide2, fSide3, fSide4); bRect = Rect(fSide1, fSide2, fSide3, fSide4); Print(fSide1, fSide2, fSide3, fSide4, fPeri, bSquare, bRect); cout << "Would you like to do this again?" << endl << endl; cin >> cAgain; }while(cAgain == 'Y' || cAgain == 'y'); return 0; } void GetData(float &fSide1, float &fSide2, float &fSide3, float &fSide4) { bool bDataGood = 0; do { cout << "Enter the four sides of the object, seperated by a space" << endl << endl; cin >> fSide1 >> fSide2 >> fSide3 >> fSide4; cout << endl << endl; if(fSide1 <= 0||fSide2 <= 0 || fSide3 <= 0 || fSide4 <= 0) cout << "One or more numbers are invalid" << endl << endl; else bDataGood = TooSmall(fSide1, fSide2, fSide3, fSide4); } while(!bDataGood); return; } bool TooSmall(float fSide1, float fSide2, float fSide3,float fSide4) { float fSide1, fSide2, fSide3, fSide4; bool bDataGood; if(fSide1 >= (fSide2 + fSide3 + fSide4)) cout << "Side 1 is too long." << endl << endl; else if(fSide2 >= (fSide1 + fSide3 + fSide4)) cout << "Side 2 is too long." << endl << endl; else if(fSide3 >= (fSide2 + fSide1 + fSide4)) cout << "Side 2 is too long." << endl << endl; else if(fSide4 >= (fSide2 + fSide3 + fSide1)) cout << "Side 2 is too long." << endl << endl; else bDataGood = true; return bDataGood; } float Perimeter(float fSide1, float fSide2, float fSide3, float fSide4) { float fSide1, fSide2, fSide3, fSide4, fPeri; fPeri = fSide1 + fSide2 + fSide3 + fSide4; return fPeri; } bool isSquare(float fSide1,float fSide2,float fSide3,float fSide4) { float fSide1, fSide2, fSide3, fSide4; bool bSquare; if(fSide1 == fSide2 && fSide2 == fSide3 && fSide3 == fSide4) bSquare = true; if(fSide1 != fSide2 || fSide2 != fSide3 || fSide3 != fSide4) bSquare = false; return bSquare; } bool isRect(float fSide1, float fSide2,float fSide3,float fSide4) { float fSide1, fSide2, fSide3, fSide4; bool bRect; if (fSide1 == fSide3 && fSide2 == fSide4) bRect = true; if (fSide1 != fSide3 || fSide2 != fSide4) bRect = false; return bRect; } void Print(float fSide1,float fSide2,float fSide3,float fSide4,float fPeri,bool bSquare,bool bRect) { float fSide1, fSide2, fSide3, fSide4, fPeri; bool bSquare, bRect; cout << "Results:" << endl << "Length of Side 1: " << fSide1 << endl << "Length of Side 2: " << fSide2 << endl << "Length of Side 3: " << fSide3 << endl << "Length of Side 4: " << fSide4 << endl << "Object Perimeter: " << fPeri << endl; if (bSquare) cout << "The object is a square" << endl; else if (!bSquare) cout << "The object is not a square" << endl; if (bRect) cout << "The object is a rectangle" << endl; else if (!bRect) cout << "The object is not a rectangle" << endl; return; } Here are my errors lab9a.cpp: In function `int main()': lab9a.cpp:29: error: `Square' was not declared in this scope lab9a.cpp:30: error: `Rect' was not declared in this scope lab9a.cpp:29: warning: unused variable 'Square' lab9a.cpp:30: warning: unused variable 'Rect' lab9a.cpp: In function `bool TooSmall(float, float, float, float)': lab9a.cpp:60: error: declaration of 'float fSide1' shadows a parameter lab9a.cpp:60: error: declaration of 'float fSide2' shadows a parameter lab9a.cpp:60: error: declaration of 'float fSide3' shadows a parameter lab9a.cpp:60: error: declaration of 'float fSide4' shadows a parameter lab9a.cpp: At global scope: lab9a.cpp:59: warning: unused parameter 'fSide1' lab9a.cpp:59: warning: unused parameter 'fSide2' lab9a.cpp:59: warning: unused parameter 'fSide3' lab9a.cpp:59: warning: unused parameter 'fSide4' lab9a.cpp: In function `float Perimeter(float, float, float, float)': lab9a.cpp:78: error: declaration of 'float fSide1' shadows a parameter lab9a.cpp:78: error: declaration of 'float fSide2' shadows a parameter lab9a.cpp:78: error: declaration of 'float fSide3' shadows a parameter lab9a.cpp:78: error: declaration of 'float fSide4' shadows a parameter lab9a.cpp: At global scope: lab9a.cpp:77: warning: unused parameter 'fSide1' lab9a.cpp:77: warning: unused parameter 'fSide2' lab9a.cpp:77: warning: unused parameter 'fSide3' lab9a.cpp:77: warning: unused parameter 'fSide4' lab9a.cpp: In function `bool isSquare(float, float, float, float)': lab9a.cpp:86: error: declaration of 'float fSide1' shadows a parameter lab9a.cpp:86: error: declaration of 'float fSide2' shadows a parameter lab9a.cpp:86: error: declaration of 'float fSide3' shadows a parameter lab9a.cpp:86: error: declaration of 'float fSide4' shadows a parameter lab9a.cpp: At global scope: lab9a.cpp:85: warning: unused parameter 'fSide1' lab9a.cpp:85: warning: unused parameter 'fSide2' lab9a.cpp:85: warning: unused parameter 'fSide3' lab9a.cpp:85: warning: unused parameter 'fSide4' lab9a.cpp: In function `bool isRect(float, float, float, float)': lab9a.cpp:97: error: declaration of 'float fSide1' shadows a parameter lab9a.cpp:97: error: declaration of 'float fSide2' shadows a parameter lab9a.cpp:97: error: declaration of 'float fSide3' shadows a parameter lab9a.cpp:97: error: declaration of 'float fSide4' shadows a parameter lab9a.cpp: At global scope: lab9a.cpp:96: warning: unused parameter 'fSide1' lab9a.cpp:96: warning: unused parameter 'fSide2' lab9a.cpp:96: warning: unused parameter 'fSide3' lab9a.cpp:96: warning: unused parameter 'fSide4' lab9a.cpp: In function `void Print(float, float, float, float, float, bool, bool)': lab9a.cpp:108: error: declaration of 'float fSide1' shadows a parameter lab9a.cpp:108: error: declaration of 'float fSide2' shadows a parameter lab9a.cpp:108: error: declaration of 'float fSide3' shadows a parameter lab9a.cpp:108: error: declaration of 'float fSide4' shadows a parameter lab9a.cpp:108: error: declaration of 'float fPeri' shadows a parameter lab9a.cpp:109: error: declaration of 'bool bSquare' shadows a parameter lab9a.cpp:109: error: declaration of 'bool bRect' shadows a parameter lab9a.cpp: At global scope: lab9a.cpp:107: warning: unused parameter 'fSide1' lab9a.cpp:107: warning: unused parameter 'fSide2' lab9a.cpp:107: warning: unused parameter 'fSide3' lab9a.cpp:107: warning: unused parameter 'fSide4' lab9a.cpp:107: warning: unused parameter 'fPeri' lab9a.cpp:107: warning: unused parameter 'bSquare' lab9a.cpp:107: warning: unused parameter 'bRect' Any help would be greatly appreciated. Last edited by renimRMU : 05-03-2008 at 11:21 PM. Reason: wrong code |
|
|
|
![]() |
| Thread Tools | |
|
|