Speeding and fines

Here is my problem: I just can't get it to work. I get different errors depending on what I do. I have left some things I have tried on thats why I have all the //.

1. Create a program that allows the State Highway Patrol to make the proper decision regarding your speed on I-74 as you were heading home tonight.
a. Prompt the user for the speed the vehicle was traveling
b. If the speed was over the posted limit of 65, calculate the fine based on $10 for every mph over the limit.
c. Output the amount of the fine with an appropriate message to the user
d. If the speed was too low, output an appropriate message
e. If the speed was exact, output an appropriate message



#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
int main()
{

   double speed = 0;
  // double limit = 65;
   double fine = 10;

  
cout << "Input speed of vehicle: ";
cin >> speed;


//fine = ((speed - limit) * 10);
//cin >> fine >> endl;

if (speed > 65)
{cout << "You should slow down " << endl;
fine = ((speed - limit) * 10);

//cout << "Your fine is ";
//cin >> fine >> endl;
}  
else if (speed >= 40)
{cout << "You are doing a great job " << endl;
//fine = 0
}
else if (speed <= 39)
{cout << "You need to speed up " << endl;
//fine = 0


}

     
    system("pause"); //holds the command window open
    return 0; //ends the program
}

Last edited on
1) Please use code tags to make your code readable:

http://www.cplusplus.com/articles/z13hAqkS/

2) We're not mind-readers. Please be specific about what problem you're seeing, and what errors you're getting. That will make it easier for us to help you.
I can't get it to calculate the fine when speed is over 65, I keep getting an error
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

int main()
{

    double speed = 0;
    double limit = 65;
    double yourfine = 0;
    double fine = 10;


    cout << "Input speed of vehicle: ";
    cin >> speed;


//fine = ((speed - limit) * 10);
//cin >> fine >> endl;

    if (speed > limit)
    {
        cout << "You should slow down " << endl;
        yourfine = ((speed - limit) * fine);

        cout << "Your fine is $";
        cout << yourfine << endl;
    }
    else if (speed >= 40)
    {
        cout << "You are doing a great job " << endl;
//fine = 0
    }
    else if (speed <= 39)
    {
        cout << "You need to speed up " << endl;
//fine = 0

    }

    system("pause"); //holds the command window open
    return 0; //ends the program
}
Topic archived. No new replies allowed.