Beginner Programmer looking for help on project please

This is a discussion on Beginner Programmer looking for help on project please within the C++ Programming forums, part of the General Programming Boards category; I am continually looking over my notes and book trying to figure this out but i cant seem to find ...

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    2

    Beginner Programmer looking for help on project please

    I am continually looking over my notes and book trying to figure this out but i cant seem to find what i need.

    the project is to compile a automated speeding ticket

    [Note: Checkpoint A and B are always 5 miles apart]
    Ticket prices are calculated as follow: base + fee*<number of mph over the speed limit>. The base is $150 and the fee per mph over the speed limit is $5. Time is kept in the number of minutes past midnight, so 10AM is 10hours * 60 minutes = 600, 10:30AM = 630, 10PM = 60(12+10) = 1320. Speed should be truncated, so a car moving 4.341 will be calculated at 4mph.

    program should accept these inputs:

    License plate number
    Time at Checkpoint A (in minutes)
    Time at Checkpoint B (in minutes)
    Speed limit in time zone


    currently all i really have is the basic in and out commands, and i believe the formula for the checkpoints. can anyone with some time please look over my program and help me get started in the right direction? I cant seem to get the if else if statement to work.

    for example if input the following
    CheckpointA: 1230
    CheckpointB: 1237
    Speed Limit: 55

    it should report that no ticket is issued... however my program continues to give a ticket

    Code:
    
    #include <iostream>
    #include <iomanip>
    #include <string>
    
    
    using namespace std;
    
    
    int main()
    
    
    {
    string license; 
    double base = 150, fee = 5, ticket;
    int mph, timeA, timeB;
    
    
    cout << "Enter license plate number" << endl;
    
    
    cin >> license;
    
    
    cout << "Enter time at Checkpoint A" << endl;
    
    
    cin >> timeA;
    
    
    cout << "Enter time at Checkpoint B" << endl;
    
    
    cin >> timeB;
    
    
    cout << "Enter speed limit in the zone" << endl;
    
    
    cin >> mph;
    
    
    if(mph < (timeB - timeA)*12) 
    {
    ticket = base + fee * ((timeB-timeA)*12- mph);
    cout << "A ticket of $" << ticket << " is issued to " << license << endl;
    }
    else
    cout << "No ticket issued" << endl;
    
    
    return 0;
    }
    Last edited by champaned_our; 03-20-2012 at 02:47 AM.

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,648
    it should report that no ticket is issued... however my program continues to give a ticket
    Check your assumptions. Simple math: If you travel 5 miles in 7 minutes, how fast are you going?
    Last edited by rags_to_riches; 03-20-2012 at 04:36 AM.

  3. #3
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,648
    And proof why I should have at least two cups of coffee before attempting basic math! What a dumbass I am. Sorry. I reversed it to 7 miles in 5 minutes.

    5 miles/7 minutes = x miles/60 minutes
    7x = 300
    x = 42.86 mph

    So you need to fix your math is all.

  4. #4
    Registered User
    Join Date
    Mar 2012
    Posts
    2
    ^
    thanks for the pointers
    now i think i got the math portion figured out... but now im having trouble with the ticket being calculated properly.. this what i have as of right now..

    the price of the ticket comes out incorrectly.. as well as reporting that tickets arent issued when they should be... im almost sure that my if statement is not set correctly

    Code:
    #include <iostream>
    #include <iomanip>
    #include <string>
    
    
    using namespace std;
    
    
    int main()
    
    
    {
    string license; 
    double base = 150, fee = 5, ticket;
    int mph, timeA, timeB, Speed = 0, Time_Taken = 0,diffSpeed = 0;
    
    
        cout << "Enter license plate number" << endl;
    
    
        cin >> license;
    
    
        cout << "Enter time at Checkpoint A" << endl;
    
    
        cin >> timeA;
    
    
        cout << "Enter time at Checkpoint B" << endl;
    
    
        cin >> timeB;
    
    
        cout << "Enter speed limit in the zone" << endl;
    
    
        cin >> mph;
    
    
    
    
        Time_Taken = timeB - timeA;
        Speed = (5 / Time_Taken ) *60 + 0.5; 
    
    
        diffSpeed = mph - Speed;
    
    
        if ( diffSpeed > mph )
        {
        ticket = base + fee * diffSpeed;
    
    
        cout << "A ticket of $" << ticket << " is issued to " << license << endl;
    }
        else
        cout << "No ticket issued" << endl;
    
    
    return 0;
    
    
    }

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,288
    5 divided by 7 gives you zero, with a remainder of 5 which is ignored.
    Either do the multiplication first so that it's five times sixty, divided by seven, or make sure one of the operands is a floating point type.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help! Beginner Programmer....
    By Shodai100 in forum C++ Programming
    Replies: 6
    Last Post: 09-10-2010, 02:54 AM
  2. Help. Beginner Programmer
    By n4rush0 in forum C Programming
    Replies: 16
    Last Post: 08-25-2010, 03:04 AM
  3. Beginner programmer
    By Kool4School in forum C Programming
    Replies: 16
    Last Post: 11-24-2008, 12:16 PM
  4. Beginner Programmer
    By silverjump in forum C++ Programming
    Replies: 2
    Last Post: 04-04-2005, 06:03 PM
  5. Any beginner C++ programmer wants to.....
    By incognito in forum C++ Programming
    Replies: 5
    Last Post: 12-06-2001, 07:15 AM

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