C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 21st, 2006, 09:42 PM
dajohnson1s dajohnson1s is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2006
Posts: 1 dajohnson1s User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 12 sec
Reputation Power: 0
Help with C++ Program

I just wanted to say that I am new to C++ and greatly accept any suggestions.

I have been working on this program for awhile and can't for the life of me figure out what is going wrong. Everybody else in my class is having the same issue as I am.

What I am supposted to be doing is creating a library with functions that are given to me, I believe the .h file is correct and i can get the functions.cpp file to compile without errors, but when I compile the driver (spent hours trying to figure out) i get errors, out of frustration I think I have screwed up my program...

this is the driver section

#include <iostream>
#include <cmath>
using namespace std;

#include "geometry.h"



int main ()
{

char circle = 'c';
char rectangle = 'r';
char triangle = 't';
char variable;
double radius;
double sideOne;
double sideThree;
double sideTwo;

cout << "enter a variable to calculate area and perimeter
(c = circle, r = rectangle, t = triangle) :";
cin >> variable;

if(variable == c)
{
cout << "\nEnter radius";
cin >> radius;
cout << "Area is: " << areaOFCircle(PI, radius);
cout << "\nPerimeter is: " << circumferenceOFCirle(PI, radius);
}
else if(variable == r)
{
cout <<"\nEnter side one";
cin >> sideOne;
cout << "\nEnter side two";
cin >> sideTwo;
cout << "\nEnter side three";
cin >> sideThree;
cout << "Area is: " << areaOfSquare(sideOne, sideTwo);
cout << "\nPerimeter is: " << perimeterOfSquare(sideOne, sideTwo);
}
else if(variable == t)
{
cout <<"\nEnter side one";
cin >> sideOne;
cout << "\nEnter side two";
cin >> sideTwo;
cout << "\nEnter side three";
cin >> sideThree;
cout << "Area is: " << perimeterOfTriangle(sideOne, sideTwo, sideThree);
cout << "Perimeter is: " << areaOfTriange(sideOne, sideTwo, sideThree);
}
}
Here are my functions:

circumferenceOFCirle(double PI, double radius)
{
return(2 * PI * radius);
}

areaOFCircle(double PI, double radius)
{
return(PI * (pow(radius,2)));
}

/************************************************/

perimeterOfSquare(double sideOne, double sideTwo)
{
return((2 * sideOne) + (2 * sideTwo));
}
areaOfSquare(double sideOne, double sideTwo)
{
return(sideOne * sideTwo);
}

/***********************************************/

perimeterOfTriangle(double sideOne, double sideTwo, double sideThree)
{
return(sideOne + sideTwo + sideThree);
}
areaOfTriangle(double sideOne, double sideTwo, double sideThree)
{

return(sqrt((( sideOne + sideTwo + sideThree)/2) * ((( sideOne + sideTwo + sideThree)/2) - sideOne) * (((sideOne + sideTwo + sideThree)/2) - sideTwo) * (((sideOne + sideTwo + sideThree)/2) - sideThree)));
}

any suggestions?

also, when I compile this I get an error saying that c,t,r are undeclaired identifiers...could anybody clear this up for me?

Reply With Quote
  #2  
Old February 22nd, 2006, 12:28 AM
Cirus Cirus is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 276 Cirus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 11 h 48 m 58 sec
Reputation Power: 4
Quote:
Originally Posted by dajohnson1s
I just wanted to say that I am new to C++ and greatly accept any suggestions.

I have been working on this program for awhile and can't for the life of me figure out what is going wrong. Everybody else in my class is having the same issue as I am.

What I am supposted to be doing is creating a library with functions that are given to me, I believe the .h file is correct and i can get the functions.cpp file to compile without errors, but when I compile the driver (spent hours trying to figure out) i get errors, out of frustration I think I have screwed up my program...

this is the driver section

#include <iostream>
#include <cmath>
using namespace std;

#include "geometry.h"



int main ()
{

char circle = 'c';
char rectangle = 'r';
char triangle = 't';
char variable;
double radius;
double sideOne;
double sideThree;
double sideTwo;

cout << "enter a variable to calculate area and perimeter
(c = circle, r = rectangle, t = triangle) :";
cin >> variable;

if(variable == c)
{
cout << "\nEnter radius";
cin >> radius;
cout << "Area is: " << areaOFCircle(PI, radius);
cout << "\nPerimeter is: " << circumferenceOFCirle(PI, radius);
}
else if(variable == r)
{
cout <<"\nEnter side one";
cin >> sideOne;
cout << "\nEnter side two";
cin >> sideTwo;
cout << "\nEnter side three";
cin >> sideThree;
cout << "Area is: " << areaOfSquare(sideOne, sideTwo);
cout << "\nPerimeter is: " << perimeterOfSquare(sideOne, sideTwo);
}
else if(variable == t)
{
cout <<"\nEnter side one";
cin >> sideOne;
cout << "\nEnter side two";
cin >> sideTwo;
cout << "\nEnter side three";
cin >> sideThree;
cout << "Area is: " << perimeterOfTriangle(sideOne, sideTwo, sideThree);
cout << "Perimeter is: " << areaOfTriange(sideOne, sideTwo, sideThree);
}
}
Here are my functions:

circumferenceOFCirle(double PI, double radius)
{
return(2 * PI * radius);
}

areaOFCircle(double PI, double radius)
{
return(PI * (pow(radius,2)));
}

/************************************************/

perimeterOfSquare(double sideOne, double sideTwo)
{
return((2 * sideOne) + (2 * sideTwo));
}
areaOfSquare(double sideOne, double sideTwo)
{
return(sideOne * sideTwo);
}

/***********************************************/

perimeterOfTriangle(double sideOne, double sideTwo, double sideThree)
{
return(sideOne + sideTwo + sideThree);
}
areaOfTriangle(double sideOne, double sideTwo, double sideThree)
{

return(sqrt((( sideOne + sideTwo + sideThree)/2) * ((( sideOne + sideTwo + sideThree)/2) - sideOne) * (((sideOne + sideTwo + sideThree)/2) - sideTwo) * (((sideOne + sideTwo + sideThree)/2) - sideThree)));
}

any suggestions?

also, when I compile this I get an error saying that c,t,r are undeclaired identifiers...could anybody clear this up for me?



In the if , else if and else conditions instead of writing
if (variable == t) write if(variable = 't') .

Remember, t is is cahracter rather than a variable.If your remove quotes, error wil come.

Reply With Quote
  #3  
Old February 22nd, 2006, 01:23 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Click here for more information.
 
Join Date: Sep 2005
Posts: 790 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 4 Days 41 m 4 sec
Reputation Power: 4
I agree, c, t, and r are not variables in your program. circle, rectangle, and triangle are (with respective values, 'c', 't', and 'r'). So what I think your teacher wants to see (and I concur) is:
if( variable == circle ) ..
if( variable == rectangle ) ..
if( variable == triangle ) ..

Good luck!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Help with C++ Program


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT