when running program I receive an error "runtime check failure #3

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
      cout.precision(2);
      cout.setf(ios::fixed);
      //****INITIALIZE****
      int            Shares;                                          
                double      MarketPrice;                                    
                double      CommissionFee = 0.02;            
      double      CommissionMinimumFee = 32.95;      
      double      MarketValue      = MarketPrice * Shares;                  
                double      CommissionPaid = CommissionFee * Shares;      
      
      //****PROGRAM TITLE*****
      cout << "\t\t\t**********STOCK PROGRAM**********\n\n"<<endl;
      
      //****USER INPUT*****                              
      cout << "Please enter amount of shares:  "<<endl;
      cin >> Shares;

      cout << "Please enter price per share:   "<<endl;
      cin >> MarketPrice;
      
      //****DISPLAY*****
      cout << "Shares:\t\t\t " << Shares << endl;
      cout << "Market Price Per Share:\t $" << MarketPrice << endl;
      cout << "Commission Fee:\t\t $" << CommissionFee << endl;
      cout << "Commission Minimum Fee:\t $" <<CommissionMinimumFee << endl;

      cout<< "\n\nMarket Value:\t\t $" << MarketValue << endl;
      
      //****CONDITIONAL STATEMENT*****
      if (CommissionPaid < CommissionMinimumFee) {
      
            cout << "Commission Paid:\t$" <<CommissionMinimumFee << endl;
      }
      else if (CommissionPaid > CommissionMinimumFee) {
            
            cout <<"Commission Paid:\t$" <<CommissionPaid<< endl;
            
      }

cin.ignore();
cin.ignore();
//*****END PROGRAM*****
}
mmorse0971Asked:
Who is Participating?
 
jkrConnect With a Mentor Commented:
Try to initialize all your variables before using them, e.g.

     //****INITIALIZE****
    int          Shares = 0;                                  
                double     MarketPrice = 0.0;      

And, do the calculations *after* the user has entered the values:

int main()
{
    cout.precision(2);
    cout.setf(ios::fixed);
    //****INITIALIZE****
    int          Shares;                                  
                double     MarketPrice;                              
               double     CommissionFee = 0.02;          

    //****PROGRAM TITLE*****
    cout << "\t\t\t**********STOCK PROGRAM**********\n\n"<<endl;
   
     //****USER INPUT*****                        
     cout << "Please enter amount of shares:  "<<endl;
    cin >> Shares;

    cout << "Please enter price per share:   "<<endl;
    cin >> MarketPrice;
   
    double     CommissionMinimumFee = 32.95;    
     double     MarketValue     = MarketPrice * Shares;              
                double     CommissionPaid = CommissionFee * Shares;    
     
     //****DISPLAY*****
    cout << "Shares:\t\t\t " << Shares << endl;
    cout << "Market Price Per Share:\t $" << MarketPrice << endl;
    cout << "Commission Fee:\t\t $" << CommissionFee << endl;
     cout << "Commission Minimum Fee:\t $" <<CommissionMinimumFee << endl;

    cout<< "\n\nMarket Value:\t\t $" << MarketValue << endl;
   
     //****CONDITIONAL STATEMENT*****
    if (CommissionPaid < CommissionMinimumFee) {
   
          cout << "Commission Paid:\t$" <<CommissionMinimumFee << endl;
    }
    else if (CommissionPaid > CommissionMinimumFee) {
         
         cout <<"Commission Paid:\t$" <<CommissionPaid<< endl;
         
    }

cin.ignore();
cin.ignore();
//*****END PROGRAM*****
}

which produces:

                        **********STOCK PROGRAM**********


Please enter amount of shares:
5
Please enter price per share:
1.20
Shares:                  5
Market Price Per Share:  $1.20
Commission Fee:          $0.02
Commission Minimum Fee:  $32.95


Market Value:            $6.00
Commission Paid:        $32.95

Apart from that, the above runs fine here.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.