Answer on Question #44452, Programming, C++
Problem.
Your city's parking violation bureau wants you to write a program to compute fines for parking violations. There are four types of violation: type A carries a fine of 20, type C carries a fine of 50. The program should ask for the number of type A violations, the number of type B violations, and so on. The program should display the total fine for the person.
Solution.
Code
#include <iostream>
using namespace std;
int main() {
// number of type A violations
int A;
// number of type B violations
int B;
// number of type C violations
int C;
// number of type D violations
int D;
cout << "Enter the number of type A violations: ";
cin >> A;
cout << "Enter the number of type B violations: ";
cin >> B;
cout << "Enter the number of type C violations: ";
cin >> C;
cout << "Enter the number of type D violations: ";
cin >> D;
// total fine
int fine = 10 * A + 20 * B + 30 * C + 50 * D;
cout << "Total fine: $" << fine;
return 0;
}Result
Enter the number of type B violations: 1
Enter the number of type D violations: 2
Enter the number of type C violations: 3
Enter the number of type D violations: 4
Total fine: $348
Process returned 8 (8x8) execution time : 3.336 s
Press any key to continue.http://www.AssignmentExpert.com/</iostream>