Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
#include <iostream>

using namespace std;

int main()
{

const double KM5_FEE= 65.00;
const double KM10_FEE = 100.00;
const double KM15_FEE= 150.00;
double income_5=0;
double income_10=0;
double income_15;
int count_fee5=0;
int count_fee10 = 0;
int count_fee15 =0;
char answer;
int choice;
int total_income=0;
int total_part=0;
int highest_cat;


  cout<<"Fun Run Competition"<<endl;
   cout<<" Do you want to register a participant( Y or N):";
    cin>>answer;

    while(answer != 'N' && answer != 'n')
    {
        cout<<"Categories\n"
            <<"1. 5 kilometres\n"
            <<"2. 10 kilometres\n"
            <<"3. 15 kilometres\n";
            cout<<" Your choice(1/2/3):";
            cin>> choice;

            switch(choice)
            {
                case 1:
                income_5 = income_5+ KM5_FEE;
                count_fee5++;
                break;

                case 2:
                income_5 = income_10+ KM5_FEE;
                count_fee10++;
                break;

                case 3:
                income_5 = income_15+ KM5_FEE;

                count_fee15++;
                break;
                default:
                cout<<"invalid category entered/n"
                    <<"Registration cancelled";
                break;
                cout<<"Do you want to register another participant( Y or N)";
                cin>>answer;

            }
            if(count_fee5>count_fee10&& count_fee5>count_fee15)
            {
                highest_cat = highest_cat+ 5;
            }
            else if (count_fee10>count_fee5&& count_fee10>count_fee15)
            {
                highest_cat= highest_cat+ 10;
            }
            else
            {
             highest_cat= highest_cat+ 15;
             }
            total_income = total_income+ income_15+ income_5+income_10;
            total_part = total_part + count_fee5+ count_fee10+ count_fee15;

            cout<<"Registration per category\n";
            cout<<"Category\tNumber of Athletes\tIncome";
            cout<<"5 kilometres\t"<<count_fee5<<"\t"<<income_5;
            cout<<"10 kilometres\t"<<count_fee10<<"\t"<<income_10;
            cout<<"15 kilometres\t"<<count_fee15<<"\t"<<income_15;
            
            cout<<"The total number of participants:"<<total_part;
            cout<<"Total income"<< total_income;
            cout<<"Category with the highest income"<<highest_cat;



}


What I have tried:

I have tried evrything and its giving me the wrong the output, the logic is wrong.
Posted
Updated 12-Aug-22 6:27am
Comments
Rick York 12-Aug-22 12:36pm    
one other thing - in your default case there is a break in the middle of some logic and that makes the prompt and input statements unreachable. Also, the final listings should probably happen only after all participants are registered. This means you should rearrange your loop and prompting.
merano99 12-Aug-22 14:44pm    
Wrong Output? In this case, there are still very many errors in it, which make the process almost impossible. But it would also be good if you provide data documenting the errors and also write what you would have expected as outputs.

Quote:
I have tried evrything and its giving me the wrong the output, the logic is wrong.

Look at your code !
C++
case 1:
income_5 = income_5+ KM5_FEE;
count_fee5++;
break;

case 2:
income_5 = income_10+ KM5_FEE;
count_fee10++;
break;

case 3:
income_5 = income_15+ KM5_FEE;

Be careful, everything matters.
 
Share this answer
 
Quote:
its giving me the wrong the output

There are already some anomalies even without data, which Patrice T has already noted.
Here, for example:
C++
double income_5=0;
double income_10=0;
double income_15;

Variable income_15 is not initialised, and also you should initialize with a double and not with an integer.
 
Share this answer
 
v2
Comments
Patrice T 12-Aug-22 11:55am    
Didn't see that one :)
+5
merano99 12-Aug-22 14:32pm    
Thanks!
I think you have the answers by now. Since this is C++, I wanted to point out something about your code. You have a set of variables declared :
C++
const double KM5_FEE= 65.00;
const double KM10_FEE = 100.00;
const double KM15_FEE= 150.00;
double income_5=0;
double income_10=0;
double income_15;
int count_fee5=0;
int count_fee10 = 0;
int count_fee15 =0;
and to me they appear to lend themselves to a class organization. Something like this :
C++
class Entry
{
public:  // members
    double  m_fee     { 0 };
    double  m_income  { 0 };
    double  m_count   { 0 };

public:  // methods
    Entry() {}  // default constructor

    // assignment constructor

    Entry( double fee, double income=0, double count=0 )
    {
        Set( fee, income, count );
    }

    void Set( double fee, double income=0, double count=0 )
    {
        m_fee = fee;
        m_income = income;
        m_count = count;
    }

    void Register()
    {
       m_income += m_fee;
       ++m_count;
    }
};
to construct some you can do this :
C++
Entry entry05( 65 );
Entry entry10( 100 );
Entry entry15( 150 );
this will make the switch statement in your code look like this :
C++
switch(choice)
{
    case 1:
       entry05.Register();
       break;

    case 2:
       entry10.Register();
       break;

    case 3:
       entry15.Register();
       break;
}
I will leave this rest of it for you to figure out.

This is just something for you to consider since you have classes available to you. I think the use of a class for this can simplify your logic considerably.
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900