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:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* 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
Go Back   Tech Support Forum > The Conversation Pit > Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read

Programming A discussion forum for programs and programming used in tech-related businesses.

Reply
 
Thread Tools
Old 05-03-2008, 11:19 PM   #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
renimRMU is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -7. The time now is 08:43 PM.



Copyright 2001 - 2008, Tech Support Forum

Search Engine Friendly URLs by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81