![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: May 2006
Posts: 85
Rep Power: 3
![]() |
C++ program help please!!!
#include "05-03.h"
#include <iostream>
using namespace std;
int main()
{
// Call the menu to cause it to display initially
menu(); /* RIGHT HERE IS WHERE THE PROBLEM IS */
system ("PAUSE");
cin.get();
return 0;
}
void menu()
{
int menuchoice;
float radius, height, width, base, answer;
char somechar;
/* This first section simply displays the users choices
then prompts the user to make a selection. */
cout << "1. Area of a circle \n";
cout << "2. Area of a triangle \n";
cout << "3. Area of a rectangle";
cout << "4. Exit \n";
cout << "\n Please enter the number of your selection. \n";
cin >> menuchoice; // Whatever the users choice is
switch (menuchoice)
{
case 1:
cout << "Please enter the radius of the circle \n";
cin >> radius;
answer = circle_area(radius);
break;
case 2:
cout << "Please enter the radius of the triangle \n";
cin >> base;
cout << "Please enter the hight of the triangle \n";
cin >> height;
answer = triangle_area(base, height);
break;
case 3:
cout << "Please enter the height of the rectangle \n";
cin >> height;
cout << "Please enter the width fo the rectangle \n";
cin >> width;
answer = rectangle_area(height, width);
break;
case 4:
return;
default:
cout << "Sorry, that was not a valid entry. Please try again \n";
menu();
}
cout << "The answer is " << answer << "\n";
cout << " Press the enter /return key to continue \n";
cin >> somechar ;
menu();
}
float circle_area(float radius)
{
float area;
area = 3.14 * ( radius * radius );
return area;
}
float triangle_area(float height, float base)
{
float area;
area = .5 * (base * height);
return area;
}
float rectangle_area(float height, float width)
{
float area;
area = height * width;
return area;
}whats up with is code... look at were it says /* THIS IS WERE THE PROBLEM IS */ and thats were I get an error when I compile it...
__________________
Code Forums |
|
|
|
|
|
#2 |
|
Sexy Programmer
|
I am no C++ expert nor programmer but don't you have to define the function before using it within your class? Try this, I may be wrong, I don't know.
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
#3 |
|
Programmer
Join Date: May 2006
Posts: 85
Rep Power: 3
![]() |
lmfao I just figured it out... I was missing a letter in the header file...
__________________
Code Forums |
|
|
|
|
|
#4 |
|
Programmer
Join Date: Apr 2006
Location: Calgary, Alberta
Posts: 67
Rep Power: 3
![]() |
You might want to take a look at your menu function though. From what I gather, it appears to be recursive, which makes no sense, and could really hurt you.
Try making menu() return an int, and in your main function have: int i = menu();
while(i != 4)
{
i = menu();
}
//end program hereThis way main will call a new instance of menu() when nessecary. In your current version, you could have an infinite number of instances of menu() at any given point. |
|
|
|
|
|
#5 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Quote:
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
|
#6 |
|
Newbie
|
Mask420 you just are testing to see how good whe are. please when you need any real help, post your problem. thank you
|
|
|
|
|
|
#7 |
|
Programmer
Join Date: May 2006
Posts: 85
Rep Power: 3
![]() |
Fuck you... I really couldn't figure it out and then I looked over every peice of code and found it ... sorry for posting it before I looked...
__________________
Code Forums |
|
|
|
|
|
#8 |
|
Programmer
Join Date: May 2006
Location: Bathroom
Posts: 43
Rep Power: 0
![]() |
msk420 That is rude peaople like you should be out of here.
|
|
|
|
|
|
#9 | |
|
Sexy Programmer
|
Quote:
EDIT: Edgar, msk420 wasn't at fault yet I don't think he should have used inapproiate language but still Skoob had no right to say something stupid like he did.
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
|
#10 | |
|
Professional Programmer
|
skoob, so far the only two posts I've read of yours have both been offensive in some way towards another member on the board. I'm not the type to warn admins about threads but this if this is going to turn into a part-time job for you then I might have to make a few changes.
msk, settle down. Saying "fuck you" to other members won't benefit you in any way and won't help you make any friends here. It will only help you make a bad impression on yourself so try to refrain. Edgar, you just joined. You don't exactly have a say... yet. But hey, niether do over half of the rest of the community either. ![]()
__________________
▄▄▄▄ Quote:
Due to incorrect calculations during the middle ages, our calendar actually begins a few years after Jesus' birth. Thus the real 6/6/6 happened a few years back. The world already ended and you missed it. Download Code::Blocks now! ▄▄▄▄ |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|