Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Help with a programming challenge (input, functions, output)

$
0
0
This is practice work for a coding contest at the school, the code is pretty bad; I'm sure there are better methods to approaching the problem, and I'm sure I mucked something (or a lot of things) up along the way. I don't think I could explain it too well, but I have provided the question booklet.

And this is the output I get based on the code I provided (which I wrote):
Posted Image


Posted Image

#include <iostream>

int speedCalc( int, int );
// a mess, the purpose of the table was to hold the threshhold information for determing fines
int fineTable[3][3]={1,20,100,21,30,270,31,31,500};

int main()
{
    int inputLimit, inputPlaneSpeed;
    std::cout <<"Enter the limit: ";
    std::cin >> inputLimit;
    std::cout <<"Enter the recorded speed of the car: ";
    std::cin >> inputPlaneSpeed;
// Might have to clear input stream? idk

    speedCalc( inputLimit, inputPlaneSpeed );

    return 0;
}

int speedCalc( int speedLimit, int planeSpeed )
{
    if ( planeSpeed < speedLimit )
    {
    std::cout <<"Congratulations, you are within the speed limit!";
    std::cin.get();
    }
    else if ( planeSpeed > speedLimit )
    {
        if ((planeSpeed >= speedLimit+fineTable[1][1]) and (planeSpeed<= speedLimit+fineTable[1][2]))
        {
            std::cout <<"You are speeding and your fine is " <<fineTable[1][3];
        }
    }
}



The images don't appear to work on the original thread post, hopefully this does.
Posted Image
Posted Image

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>