Problem with Program

This is a discussion on Problem with Program within the C++ Programming forums, part of the General Programming Boards category; Hey guys I had to write a program for a C++ class im in, There is 3 different outputs to ...

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    5

    Problem with Program

    Hey guys I had to write a program for a C++ class im in, There is 3 different outputs to perform (two early exits) and both of those work great but running the problem all the way though i do not get the follow results. Any assitance would be appreciate because I am stumped.
    Input:
    Exemptions : 5
    AGI : 258250
    Status: 2

    Output
    Line 2 = 18250
    Line 3 = 258250
    Line 4 = 250200
    Line 5 = 8050
    Line 6 = 4
    Line 7 = 0.08
    Line 8 = 1460
    Line 9 = 486.67
    Line 10 = 17763.33

    Code
    Code:
    #include <iostream>       // for I/O
    #include <iomanip>        // for formating output
    #include <cmath>          // for math fuctions
    #include <cctype>         // for Common Character Functions
    using namespace std;
    
    //Global Constants
    double EXEMPTION = 3650 ;
    double SINGLE = 166800 ;
    double MAR_OR_WIDOW = 250200 ;
    double HEAD_OF_HOUSE = 208500 ;
    double MAR_SEP = 125100 ;
    double MAR_SEP_LINE6 = 1250 ;
    double MAR_SEP_LINE6_YES = 61250 ;
    double STATUS_LINE6 = 2500 ;
    double STATUS_LINE6_YES = 122500 ;
    double LINE6 = 2433 ;
    double PERCENT_LINE7 = .02 ;
    int THREE = 3 ;
    
    //Function for No on Line 6
    int line6 (double filingStatus, double lineFive, int lineSix)
    {
        if (filingStatus == 5)
        {
            lineSix = (lineFive / MAR_SEP_LINE6) ;
            ceil (lineSix) ;
        }
        else
        {
            lineSix = (lineFive / STATUS_LINE6) ;
            ceil (lineSix) ;
        }
        return  lineSix ;
    }
    
    //Function Main calculates Sphere Volume and calls output
    int main()
    {
        // Local Variables
        double numExemp ;
        double adjGross ;
        double filingStatus ; 
        double incomeLimit ;
        double lineTwo ;
        double lineFive ;
        int lineSix ;
        double lineSeven ;
        double lineEight ;
        double lineNine ;
        double lineTen ;
        
               
       // Prompt for and read in Number of Exemptions
       cout << " Enter the number of exemptions claimed: " ;
       cin >> numExemp ;
       cout << endl << endl ;
       
       // Prompt for and read in Adjusted Gross Income
       cout << " Enter your Adjusted Gross Income (1040, line 38): " ;
       cin >> adjGross ;
       cout << endl << endl ;
       
       // Prompt for and Read in Filing Status
       cout << " 1 - Single" << endl ;
       cout << " 2 - Married, Filing Jointly" << endl ;
       cout << " 3 - Head of Household" << endl ;
       cout << " 4 - Qualifying Widow(er)" << endl ;
       cout << " 5 - Married, Filing Separately" << endl ;
       cout << " Enter your filing status from above (1-5): " ;
       cin >> filingStatus ;
       cout << endl << endl ;
       
       //Determine Income Limit 
       if (filingStatus == 1)
            incomeLimit = SINGLE ;
       else if (filingStatus == 2)
            incomeLimit = MAR_OR_WIDOW ;
       else if (filingStatus == 3)
            incomeLimit = HEAD_OF_HOUSE ;
       else if (filingStatus == 4)
            incomeLimit = MAR_OR_WIDOW ;
       else if (filingStatus == 5)
            incomeLimit = MAR_SEP ;
           
       // Calculate Line 2 (total exemptions)
       lineTwo = (EXEMPTION * numExemp) ;
       
       //Display Output Heading
       cout << setw(45) << "Deduction for Exemptions Worksheet" << endl << endl;
       
       // Test for Early Exit Condition
       if (adjGross < incomeLimit)
       {
            cout << " 1.  AGI is not over filing status amount" << endl ;
            cout << " 2.  Exemptions claimed ( " << numExemp << " x 3650):" << setw(19) << lineTwo << endl << endl ;
            cout << " ***Enter amount from worksheet line 2 on form 1040 ling 42" << endl << endl ;
            system("PAUSE") ;
            return 1 ;
       }
       else if (adjGross > incomeLimit) 
       {
            cout << " 1.  AGI is over filing status amount" << endl ;
            cout << " 2.  Exemptions claimed ( " << numExemp << " x 3650):" << setw(22) << fixed << setprecision (2) << lineTwo << endl << endl ;
       }
       
       // Display Line 3
       cout << " 3.  Adjusted gross income:" << setw(31) << adjGross << endl;
       
       // Display Line 4
       cout << " 4.  Filing status (" ;
        if (filingStatus == 1)
            cout << "single):" << setw(30) << incomeLimit << endl ;
       else if (filingStatus == 2)
            cout << "married joint):" << setw(23) << incomeLimit << endl ;
       else if (filingStatus == 3)
            cout << "head of house):" << setw(23) << incomeLimit << endl ;
       else if (filingStatus == 4)  
            cout << "widow(er)):" << setw(27) << incomeLimit << endl ;
       else if (filingStatus == 5)  
            cout << "married separate):" << setw(20) << incomeLimit << endl ;
       
       // Display Seperator
       cout << " ---------------------------------------------------------" << endl ;
       
       // Calculate Line 5 (Amount Over Filing Status)
       lineFive = (adjGross - incomeLimit) ;
       
       // Display Line Five (Amount Over Filing Status)
       cout << " 5.  Amount over:" << setw(41)<< lineFive << endl << endl ;
       
       // Format Display for 0 Decimal Places
       cout << fixed << setprecision (0);
       
       // Dixplay and Calculate Line 6
       if (filingStatus == 5)
       {
            if (lineFive > MAR_SEP_LINE6_YES)
            {
                 lineSix = (numExemp * LINE6) ;
                 cout << " 6. Excemptions allowed (" << numExemp << " X 2433):" << setw(23) << lineSix << endl << endl ;
                 cout << " ***Enter amount from worksheet line 6 on form 1040 line 42" <<endl << endl ;
                 system("PAUSE") ;
                 return 6 ;
            }
            else
            {
                line6 (filingStatus, lineFive, lineSix) ; 
                cout << " 6.  Division results:" << setw(36) << lineSix << endl ;
            } 
       }
       else 
       {
            if (lineFive > STATUS_LINE6_YES)
            {
                 lineSix = (numExemp * LINE6) ;
                 cout << " 6. Excemptions allowed (" << numExemp << " X 2433):" << setw(23) << lineSix << endl << endl ;
                 cout << " ***Enter amount from worksheet line 6 on form 1040 line 42" << endl << endl;
                 system("PAUSE") ;
                 return 6 ;
            }
            else
            {
                line6 (filingStatus, lineFive, lineSix) ;
                cout << " 6.  Division results:" << setw(36) << lineSix << endl ;
            } 
       }
       
       // Format Display for 2 Decimal Places
       cout << fixed << setprecision (2);
       
       // Display Seperator
       cout << " ---------------------------------------------------------" << endl ;
       
       // Calculate Line Seven
       lineSeven = (lineSix * PERCENT_LINE7) ;
       
       // Display Line Seven
       cout << " 7.  Multiply Line 6 by 2%:" << setw(31) << lineSeven << endl ;
       
       // Calculate Line Eight
       lineEight = (lineTwo * lineSeven) ;
       
       // Display Line Eight
       cout << " 8.  Multiply line 2 by line 7:" << setw(27) << lineEight << endl ;
       
       // Calculate Line Nine
       lineNine = (lineEight / THREE) ;
       
       // Display Line Nine
       cout << " 9.  Divide line 8 by 3.0:" << setw(32) << lineNine << endl ;
       
       // Display Seperator
       cout << " ---------------------------------------------------------" << endl ;
       
       // Calculate Line Ten
       lineTen = (lineTwo - lineNine) ;
       
       // Display Line Ten
       cout << " 10. Subtract line 9 from line 2:" << setw (25) << lineTen << endl << endl ;
       cout << " ***Enter amount from worksheet line 10 on Form 1040 line 42" << endl ;
                          
       //Pauses Program so output can be seen
       cout << endl << endl ;
       system("PAUSE") ;
       return 0 ;
    }

  2. #2
    Registered User
    Join Date
    Jul 2010
    Posts
    5
    I think my problem is in my User Defined Fuction but I am fairly new to programming and to be honest am COMPLETELY lost

  3. #3
    msh
    msh is offline
    Novice
    Join Date
    Jul 2009
    Posts
    568
    Is the value of three in danger of fluctuating?

    You should probably make your constants const.

    You're not assigning the result of line6() to anything.
    Code:
    line6 (filingStatus, lineFive, lineSix) ;    // current
    
    lineSix = line6(filingStatus, lineFive, lineSix);    // should be

  4. #4
    Registered User
    Join Date
    Jul 2010
    Posts
    5
    Thank you that worked as far as returning a value even close to what it is supposed to be but its only returning 3 and according to the assignment if it rounded up it should return 4

  5. #5
    Registered User
    Join Date
    Jul 2010
    Posts
    5
    Acutally i just got it, but thank you MSH for your help i really appreciate it.

  6. #6
    Registered User
    Join Date
    Jul 2010
    Posts
    5

    Another Program im having trouble with

    this program is not returning my insurance rate properly, not sure where i really messed up but any help would be appreciated

    Code:
    #include <iostream>       // for I/O
    #include <iomanip>        // for formating output
    #include <cmath>          // for math fuctions
    #include <cctype>         // for Common Character Functions
    using namespace std;
    
    //Global Constants
    const double MALE_RATE_ONE = 0.095 ;
    const double MALE_RATE_TWO = 0.082 ;
    const double MALE_RATE_THREE = 0.074 ;
    const double MALE_RATE_FOUR = 0.062 ;
    const double FEMALE_RATE_ONE = 0.08 ;
    const double FEMALE_RATE_TWO = 0.069 ;
    const double FEMALE_RATE_THREE = 0.058 ;
    const double FEMALE_RATE_FOUR = 0.052 ;
    const double AGE_RATE_START = 0.051 ;
    const double AGE_RATE_MID = 0.062 ;
    const double AGE_RATE_TOP = 0.075 ;
    const int GROUP_ONE_START = 14 ;
    const int GROUP_TWO_START = 17 ;
    const int GROUP_THREE_START = 22 ;
    const int GROUP_FOUR_START = 27 ;
    const int GROUP_FIVE_START = 31 ;
    const int GROUP_SIX_START = 65 ;
    const int GROUP_SIX_END = 75 ;
    const int CONV_PERCENT = 100 ;
    const int OLDER = 'O' ;
    const int MALE = 'M' ;
    const int FEMALE = 'F' ;
    
    
    //Fuction to calculate insurance rate
    double detInsRate (char gender, int driverAge, double insRate)
    {
         if (gender == OLDER)
         {
              if (driverAge > GROUP_SIX_END)
                   insRate = AGE_RATE_TOP ;
              else if (driverAge >= GROUP_SIX_START)
                   insRate = AGE_RATE_MID ;
              else 
                   insRate = AGE_RATE_START ;
              return insRate ;
         }
         else if (gender == MALE)
         {
              if (driverAge >= GROUP_FOUR_START)
                   insRate = MALE_RATE_FOUR ;
              else if (driverAge >= GROUP_THREE_START)
                   insRate = MALE_RATE_THREE ;
              else if (driverAge >= GROUP_TWO_START)
                   insRate = MALE_RATE_TWO ;
              else 
                   insRate = MALE_RATE_ONE ;
              return insRate ;
         } 
         else if (gender == FEMALE)
          {
              if (driverAge >= GROUP_FOUR_START)
                   insRate = FEMALE_RATE_FOUR ;
              else if (driverAge >= GROUP_THREE_START) 
                   insRate = FEMALE_RATE_THREE ;
              else if (driverAge >= GROUP_TWO_START) 
                   insRate = FEMALE_RATE_TWO ;
              else 
                   insRate = FEMALE_RATE_ONE ;
              return insRate ;
         }  
    }
    
           
    //Function Main 
    int main()
    {
        // Local Variables
        int driverAge ;
        char gender ;
        double insRate ;
        double vehicleValue ;
        double annualPrem ;
        
        
        // Display Program heading
        cout << " Insurance Premium Calculation Program" << endl << endl ;
        
        // Prompt for and read in Driver's age
        cout << " Enter driver's age: " ;
        cin >> driverAge ;
        cout << endl << endl ;
        
        // Determine if its Necessary to Ask for Users Age
        if (driverAge < GROUP_ONE_START)
        {
             cout << " TOO YOUNG TO DRIVE" << endl << endl ;
             system("PAUSE") ;
             return 14 ;
        }
        else if (driverAge >= GROUP_FIVE_START)
        {
             gender = 'O' ;
             insRate = (detInsRate (driverAge, gender, insRate)) ; // Calls Function to Determine Insurance Rate
        }
        else 
        {
             cout << " Enter driver's gender (M/F): " ;
             cin >> gender ;
             gender = toupper(gender) ;
             cout << endl << endl ;
             insRate = (detInsRate (driverAge, gender, insRate)) ; // Calls Function to Determine Insurance Rate
         }
        
            
        // Prompt for and read in the Vehicle's Value
        cout << " Enter vehicle value: " ;
        cin >> vehicleValue ;
        cout << endl << endl ;
        
        // Calculate insurace premium
        annualPrem = (insRate * vehicleValue) ;
        
        // Convert insRate to a Percentage
        insRate = (insRate * CONV_PERCENT) ;
        
        // Display Customers Bill
        cout << " Auto Insurance Bill" << endl << endl ;
        cout << fixed << setprecision (0) ; 
        cout << setw(19) << "Vehicle Value:" << setw(7) << vehicleValue << endl ;
        cout << fixed << setprecision (1) ;
        cout << setw(15) << "Rate Used:" << setw(10) << insRate << "%" << endl ; 
        cout << fixed << setprecision (0) ;    
        cout << setw(20) << "Annual Premium:" << setw(6)<< annualPrem << endl ;
               
       
       //Pauses Program so output can be seen
       cout << endl << endl ;
       system("PAUSE") ;
       return 0 ;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multi Thread Program Problem
    By ZNez in forum C Programming
    Replies: 1
    Last Post: 01-03-2009, 11:10 AM
  2. Program Termination Problem
    By dacbo in forum C Programming
    Replies: 3
    Last Post: 01-23-2006, 02:34 AM
  3. Inheritance and Dynamic Memory Program Problem
    By goron350 in forum C++ Programming
    Replies: 1
    Last Post: 07-02-2005, 03:38 PM
  4. Replies: 20
    Last Post: 06-13-2005, 12:53 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21