Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 131,686 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,497 people online right now. Registration is fast and FREE... Join Now!




Displays a seminar fee based on membership status and age

 
Reply to this topicStart new topic

Displays a seminar fee based on membership status and age

liko
post 15 Oct, 2008 - 02:07 AM
Post #1


New D.I.C Head

*
Joined: 19 Apr, 2008
Posts: 32

I need to make a program giving certain fees for example.

Seminar fee
10 club member less than 65 old
5 Club member at least 65 years old
20 Non-members

Just putting the age and than it showing the fee for the person. Help appreciated.

CODE

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{    
    //declare variables
    char memberStatus  = ' ';
    int age            = 0;
    int fee            = 0;

    //enter status
    cout << "Membership status (M for member or N for non-member): ";
    cin >> memberStatus;
    
    //assign seminar fee
            
    //display output
    cout << "Fee: " << fee << endl;

    return 0;
}   //end of main function

User is offlineProfile CardPM

Go to the top of the page


AmitTheInfinity
post 15 Oct, 2008 - 02:26 AM
Post #2


C Surfing ∞

Group Icon
Joined: 25 Jan, 2007
Posts: 1,012



Thanked 34 times

Dream Kudos: 125
My Contributions


You need to ask for the age in similar way you asked member status. after that you will write a small if else where you check for the conditions given.

like

if member and more than equal to 65 years old
fee is 5
else if member and less than 65 years old
fee is 10
else
fee is 20

and then you show the output, that's it!
See it's so easy. smile.gif
User is offlineProfile CardPM

Go to the top of the page

liko
post 15 Oct, 2008 - 10:35 AM
Post #3


New D.I.C Head

*
Joined: 19 Apr, 2008
Posts: 32

hmm how would i do one part in math?

if ( age<60 ) {

cout << "If age is 60 and older charge: ";
charge = age_60 * 5

else etc....

Is that a way to do one of the calculations.
User is offlineProfile CardPM

Go to the top of the page

Linkowiezi
post 16 Oct, 2008 - 04:25 AM
Post #4


D.I.C Head

**
Joined: 7 Oct, 2008
Posts: 67



Thanked 11 times
My Contributions


Well if you really want to do maths and calculate it yes you can do it like that.
I would probaby assign the fees like this(as AmitTheInfinity said):
EDIT: Just realized he didn't really said it this way... but close enough...
cpp
//  Check if the user is a member
if( memberStatus == 'M' )
{
// Check age
if( age < 65 ) // If the member is less than 65 years old...
fee = 10; // ...we charge him 10...$?
else
fee = 5; // If the member is 65 years or older his fee is 5
}
else
fee = 20; // If he isn't a member we don't bother about the age

But if you really want to do it with maths and calculate it then...
cpp
int age_60 = 2, age_65 = 1, no_member = 4, charge = 5;//  Check if the user is a member
if( memberStatus == 'M' )
{
// Check age
if( age < 65 ) // If the member is less than 65 years old...
fee = age_60 * charge; // ...we charge him 10...$?
else
fee = age_65 * charge; // If the member is 65 years or older his fee is 5
}
else
fee = no_member * charge; // If he isn't a member we don't bother about the age

You could of course do it with structs, classes, switch statements or whatever way you want to but the first example really is a simple one and a good way to go in this particular case since the simplest way is usually the best way. If you don't really have to do it any other way... or just want to just for the fun of coding wink2.gif

This post has been edited by Linkowiezi: 16 Oct, 2008 - 04:31 AM
User is online!Profile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/20/08 07:57AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month