I am so lost....

So I have an assignment for my c++ computer class. I've tried for quite a while on it and I am completely lost. In attempts to reach out to the teacher, I remembered she is on vacation and unable to help. So I turn to all of you. I had much more of this program done but I made a decisive decision to start over from the basics because I was completely lost, hoping it would help me. It didn't. Any help or recommendations is much appreciated. I'm not asking you. glorious forum posters, to do my assignment, I'm just asking if you could please help push me in the right direction. Thank you.

The Assignment question is:

Problem Description:

The HealthCare Insurance Agency determines auto insurance rates based in the driver's age, ticket history, and the value of the car. The base rate is 6% of the car value. Male drivers under the age of 25 pay an extra 17%, and female drivers under the age of 21 pay an extra 4% of the base charge. A driver with more than three tickets pays an extra $100. Write a function that calculates insurance charge rates based on this information. To test this function write a program that uses this function to calculate insurance rates for information inputted by the user

Output answers in decimal form to two places. Your program should allow the user to repeat this calculation as often as the user wishes.

Example Output:

Enter the value of the car: 12000

Enter the age of the driver: 20

Enter the sex of the driver (M or F): m

Enter the number of tickets on the drivers record : 0

The insurance rate is $842.40.

Would you like to run the program again (Y or N)? n

Required Test Cases:

Value = 15000, Age = 24, Sex = m, Tickets = 4

Value = 8500, Age = 25, Sex = m, Tickets = 3

Value = 35900, Age = 45, Sex = f, Tickets = 0

Value = 900, Age = 21, Sex = f, Tickets = 0

Value = 12000, Age = 20, Sex = f, Tickets = 4

Value = 23000, Age = 38, Sex = m, Tickets = 7

The code I have is



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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
 //Type of Assignment: Homework Assignment 6
//Problem Number: 6
//Section Number: 100
//Author: 
//Date Assigned: 10/30/2014
//Program Name: Assignment6
//File Name: Assignment6.cpp
//Time Spent on Program: 

//Purpose of Program: 


#include <iostream>
#include <iomanip>
using namespace std;

void insurance_cost(int base_rate, int car_value, char gender, int cost, int m,int age);

int main()
{
	char gender, quit_choice;
	int age, ticket_history, y = 1, n = 2, m=1, cost;
	float base_rate, car_value, ticket_fee, cost;

	cout.setf(ios::fixed | ios::showpoint);
	cout << setprecision(2);

	do
	{

		cout << "This program will tell you the insurance rate of the driver based off of the information asked" << endl;
		cout << "Enter the value of the car:" << endl;
		cin >> car_value;
		cout << "Enter the age of the driver:" << endl;
		cin >> age;
		cout << "Enter the sex of the driver (M or F):" << endl;
		cin >> gender;
		cout << "Enter the number of tickets on the drivers record:" << endl;
		cin >> ticket_history;

		insurance_cost (base_rate, car_value, gender, cost, m, age);

		cout << "Would you like to run the program again (Y or N)?" << endl;
		cin >> quit_choice;
	}
	while (quit_choice != 2);
	return 0;

}

void insurance_cost(int base_rate, int car_value, char gender, int cost, int m,int age)
{
	base_rate= (car_value*0.06);
	if (gender = 1);
		{
		cost = base_rate;
		cout << "The cost of car insurance is" << cost << endl;
		if (age < 25)
			cost = (base_rate*0.17) + base_rate;
			cout << "The cost of car insurance is" << cost << endl;
		}
}


Very incomplete I know....any help is greatly appreciated.
Thank you,
goldyn
I had much more of this program done but I made a decisive decision to start over from the basics because I was completely lost, hoping it would help me.

That was very insightful, paving a project and starting over is the right choice far more often then most people would like to admit.

The first thing that I notice is that you have the variables that are involved in calculating the cost of the insurance in main where they are not relevant. You should move base_rate, car_value, ticket_fee and cost down into "insurance_cost" where the calculations would be taking place and also move the prompt for input there to. You have the wrong data types in your function declaration and definition but since you're moving them anyway it won't matter.

You seem to have started off with meaningful variable names, you should stick with that. I don't know what 'm' is and I cannot discern what it might be from the project requirements.

Beyond that it will just be a few if && tests like:
1
2
3
4
if(toupper(gender) == 'M' && age < 25)
{
     cost = base_rate * .17;
}


And so on.
Thank you so much
Last edited on
Registered users can post here. Sign in or register to post.