Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 208

# If and Else if statments

Could someone help with the if and else if statements?

#include <iostream>
#include <iomanip>

using namespace std;

void main()
{

int            Shares                              = 100;
double      MarketPrice                        = 63.25;
double      CommissionFee                  = 0.02;
double      CommissionMinimumFee      = 32.95;

double      MarketValue                        = MarketPrice * Shares;
double      CommissionPaid                  = CommissionFee * Shares;;

//Calculations

//Diplay
cout.precision(2);
cout.setf(ios::fixed);

cout << "Shares:\t\t\t " << Shares << endl;
cout << "Market Price Per Share:\t \$" << MarketPrice << endl;
cout << "CommissionFee:\t\t \$" << CommissionFee << endl;
cout << "Commission Minimum Fee:\t \$" <<CommissionMinimumFee << endl;

cout<< "\n\nMarket Value:\t\t \$" << MarketValue << endl;
cout.setf(ios::scientific);

if (CommissionPaid < CommissionMinimumFee){

cout << "Commission Paid:  \$" << CommissionMinimumFee << endl;
}
else if (Commission Paid > CommissionMinimumFee){

cout <<"Commission Paid: \$" <<CommissionFee<< endl;
}

cin.ignore();
cin.ignore();
}
0
mmorse0971
• 4
• 3
1 Solution

Commented:
I don't see problems with your code. What exactly do you need help on?

Looking through the code, the if statement will always execute, as Shares*commision will be .02 * 100 = 2. 2 is less than ComissionMinimum of 32.95 and thus if statement will always evaluate to true. Therefore, the comission minimum will be displayed.

Other than that, I see nothing wrong with the code. For the most part...

Mactep
0

Author Commented:
error C2065: 'Commission' : undeclared identifier
error C2146: syntax error : missing ')' before identifier 'Paid'
error C2065: 'Paid' : undeclared identifier
error C2059: syntax error : ')'
error C2143: syntax error : missing ';' before '{'

I thought it was fine too but I am getting these errors and I have been trying to figure it out for a few hours.  Thought I would as for some help on this one.
0

Commented:

You have a space between Comission and Paid.

>>   else if (Commission Paid > CommissionMinimumFee){
>>         cout <<"Commission Paid: \$" <<CommissionFee<< endl;
>>     }

The compiler is now treating thhis as two identifiers and neither of them is declared. What you want is one word CommissionPaid, as it is declared as double.

Disregard the
error C2146: syntax error : missing ')' before identifier 'Paid'
and
error C2143: syntax error : missing ';' before '{'

Visual C++ gets confused sometimes.

Hope this helps.

Mactep
0

Author Commented:
It must be getting late I knew I should of looked at it again tomorrow.  Thank you.
0

Author Commented:
WHen the program runs I do not want the 33 it's taking 32.95 and rounding it off and not adding the decimal point.  How would I include that in my if statements?

#include <iostream>
#include <iomanip>

using namespace std;

void main()
{

int            Shares                              = 100;
double      MarketPrice                        = 63.25;
double      CommissionFee                  = 0.02;
double      CommissionMinimumFee      = 32.95;

double      MarketValue                        = MarketPrice * Shares;
double      CommissionPaid                  = CommissionFee * Shares;

//Diplay
cout.precision(2);
cout.setf(ios::fixed);

cout << "Shares:\t\t\t " << Shares << endl;
cout << "Market Price Per Share:\t \$" << MarketPrice << endl;
cout << "CommissionFee:\t\t \$" << CommissionFee << endl;
cout << "Commission Minimum Fee:\t \$" <<CommissionMinimumFee << endl;

cout<< "\n\nMarket Value:\t\t \$" << MarketValue << endl;
cout.setf(ios::scientific);

if (CommissionPaid < CommissionMinimumFee) {

cout << "Commission Paid:  \$" << CommissionMinimumFee << endl;
}
else if (CommissionPaid > CommissionMinimumFee) {
cout <<"Commission Paid:      \$" <<CommissionPaid<< endl;

}

cin.ignore();
cin.ignore();
}

DIPSLAYS:

Shares:                  100
Market Price Per Share:  \$63.25
CommissionFee:           \$0.02
Commission Minimum Fee:  \$32.95

Market Value:            \$6325.00
Commission Paid:  \$33

0

Commented:
No Problem. Have a good night.
Mactep
0

Commented:
>> //Diplay
>>     cout.precision(2);

The precision of two means, you only get to see the 32 or 33. Since you want 32.95, set the precision to 4:
cout.precision(4);

Mactep
0

## Featured Post

• 4
• 3
Tackle projects and never again get stuck behind a technical roadblock.