Thread: Can someone help me?

  1. #1
    Registered User
    Join Date
    Mar 2009

    Can someone help me?

    Hello guys. I'm creating a program that basically inputs the speed of a vehicle and speed limit and determines what type of fine they will get if they are speeding at all. My problem seems to be with the IF statement. I'm having trouble with it. For some reason, my formulas aren't sticking and the fine isn't being displayed.... I would love if someone could point me in the right direction. Thanks for your help.

    *Program Name   :   Speed Trap
    *Program Description: Write a program that will determine how much to fine
    *a speeder.
    *BEGIN Lab05 - Speed Trap
    *   Input Vehicle Speed
    *   Input Speed Limit
    *   Clear the screen
    *   Calc Amount Speeding
    *   If(Vehicle Is Speeding)
    *   If(Amount Speeding Is In Low Range)
    *      Fine Equals Minimum Fine
    *   Else If(Amount Speeding Is In Middle Range)
    *      Fine Equals Middle Fine
    *   Else 
    *      Fine Equals Max Fine
    *   End If
    *   Display Speeding Message
    *      Display Fine
    *   Else Not Speeding 
    *   Display Not Speeding Message 
    *   End If
    *END Lab05 - Speed Trap
    #include <iostream>
    #include <iomanip>
    using namespace std;
    int main()
        //local constants
        const int MIN_BOUND = 5;
        const int MAX_BOUND = 15;
        const int MIN_FINE = 0;
        const int MID_FINE = 50;
        const int MAX_FINE = 100;
        //local variables
        int Veh_Speed;
        int Speed_Lim;
        float Amt_Speed;
        float Fine_Amt;
        /************************start main program************************/
        // Input Vehicle Speed
        cout << "Enter the Vehicle Speed : ";
        cin >> Veh_Speed;
        // Input Speed Limit
        cout << "Enter the Speed Limit: ";
        cin >> Speed_Lim;
        //Clear the screen
        // Calc Amount Speeding
        Amt_Speed = Veh_Speed - Speed_Lim;
        // If (Vehicle Is Speeding)
            if( Amt_Speed > Speed_Lim )
           if( Amt_Speed >= MIN_BOUND && Amt_Speed < MAX_BOUND )
              Fine_Amt = MIN_FINE;
           else if( Amt_Speed >= MAX_BOUND && Amt_Speed > MAX_BOUND )
              Fine_Amt = MID_FINE;
               Fine_Amt = MAX_FINE;
        // End IF
        // Display Speeding Information
        cout << setiosflags(ios::fixed | ios::showpoint) << setprecision(1);
        cout << "\n\n\n\n";
        cout << setw(56) << "    Speed Trap                 " << "\n\n\n\n";
        cout << setw(43) << "Fine ($)                       " << setw(9) << Fine_Amt  << "\n\n";
        cout << setw(43) << "Amount Speeding (mph)          " << setw(9) << Amt_Speed << "\n\n";
        cout << "\n\n\n\n\n\n\n";
        //pause the output screen for viewing 
        return 0;
    } // end if main function

  2. #2
    Professional Chef leeor_net's Avatar
    Join Date
    Apr 2004
    Charles Town, WV
    You need to first work on how you write your topic threads. "Can someone help me?" is likely to get ignored.

    You're right about one problem at the very least -- you have an issue with your if statements. You don't have any curly braces (code blocks) around your conditional statement. If statements without braces will only execute the first statement after it as part of the conditional statement.
    - Leeor

  3. #3
    Registered User
    Join Date
    Mar 2009
    I'll write a story next time on the topic thread. Anyway, at the very least, thank you for your input.

  4. #4
    Registered User
    Join Date
    Dec 2007
    A better topic would have been "Help with if statement".

  5. #5
    Registered User
    Join Date
    Mar 2009
    after a few hours of frusteration, I figured it out. I guess that's life. Programs working fine.

Popular pages Recent additions subscribe to a feed