Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 17th, 2006, 11:58 PM   #1
msk420
Programmer
 
msk420's Avatar
 
Join Date: May 2006
Posts: 85
Rep Power: 3 msk420 is on a distinguished road
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
msk420 is offline   Reply With Quote
Old May 18th, 2006, 12:03 AM   #2
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 4 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
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!
ReggaetonKing is offline   Reply With Quote
Old May 18th, 2006, 12:04 AM   #3
msk420
Programmer
 
msk420's Avatar
 
Join Date: May 2006
Posts: 85
Rep Power: 3 msk420 is on a distinguished road
lmfao I just figured it out... I was missing a letter in the header file...
__________________
Code Forums
msk420 is offline   Reply With Quote
Old May 18th, 2006, 5:43 AM   #4
Twilight
Programmer
 
Join Date: Apr 2006
Location: Calgary, Alberta
Posts: 67
Rep Power: 3 Twilight is on a distinguished road
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 here

This 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.
Twilight is offline   Reply With Quote
Old May 18th, 2006, 7:20 AM   #5
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Quote:
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.
Please do not introduce voodoo programming to the forum. It often harms more than it helps. I don't even see what class you were referring to, for that matter.
__________________
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
DaWei is offline   Reply With Quote
Old May 18th, 2006, 1:16 PM   #6
skoob
Newbie
 
skoob's Avatar
 
Join Date: May 2006
Location: AZ
Posts: 8
Rep Power: 0 skoob is on a distinguished road
Send a message via MSN to skoob Send a message via Yahoo to skoob
Mask420 you just are testing to see how good whe are. please when you need any real help, post your problem. thank you
skoob is offline   Reply With Quote
Old May 18th, 2006, 6:56 PM   #7
msk420
Programmer
 
msk420's Avatar
 
Join Date: May 2006
Posts: 85
Rep Power: 3 msk420 is on a distinguished road
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
msk420 is offline   Reply With Quote
Old May 18th, 2006, 7:20 PM   #8
Edgar
Programmer
 
Edgar's Avatar
 
Join Date: May 2006
Location: Bathroom
Posts: 43
Rep Power: 0 Edgar is on a distinguished road
msk420 That is rude peaople like you should be out of here.
Edgar is offline   Reply With Quote
Old May 18th, 2006, 8:02 PM   #9
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 4 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
Quote:
Originally Posted by DaWei
Please do not introduce voodoo programming to the forum. It often harms more than it helps. I don't even see what class you were referring to, for that matter.
No DaWei, I read in C++, you have to define your function before you use them? Is this not true?

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!
ReggaetonKing is offline   Reply With Quote
Old May 18th, 2006, 8:17 PM   #10
jayme
Professional Programmer
 
jayme's Avatar
 
Join Date: Nov 2005
Location: Canada
Posts: 495
Rep Power: 0 jayme is an unknown quantity at this point
Send a message via MSN to jayme
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:
Originally Posted by Mohamed Jihad
Durka durka!
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!
jayme is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:49 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC