Can't Program Simple Thing

I am not a good programmer and I have no idea how to do this. I am busy and can't do it myself. Is there anyone that could program a c++ program that does this:
-You chose one of 5 cars (cars are named car 1, car 2, etc...)
-You have 4 ratings that go from 1 to 10 (Aero, Engine, Handling, Grip)
-You have just 40 points to work with
-I need that coded and I have no idea how to determine what will make you better depending on what you give as your ratings.
closed account (iG3b7k9E)
You can use an array to do this. And at the end you should have it repeat back to you what you imputed earlier.
Sounds like an interest problem for a noob such as myself. Right now I am busy but I will post what I came up with later tonight.

You will need more than a single array to accomplish this. To make this foolproof you will need a decent amount of code.

I am busy and can't do it myself

What a bullshit excuse!!!

Here is a start.

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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

struct Rating
{
	Rating (string name) 
	{ 
		_name = name;
		_rating = 0; 
	}

	bool SetRating(int rating)
	{
		if (0 <= (_rating += rating) <= 10)
		{
			_rating += rating; 
			return true;
		}

		return false;
	}

	void Print(ostream& out)
	{
		out << _name << ": " << _rating;
	}

	string _name;
	int _rating;
};


struct Car
{
	// add a name for the car
	void AddName(string name) 
	{ 
		_name = name; 
	}

	// add a rating to a car
	void AddRating(string name)
	{
		Rating tmp(name);
		_ratings.push_back(tmp);
	}
	
	// loops through ratings and uses Ratings print method
	void Print(ostream& out)
	{
		out << endl << _name << endl << endl;

		for (int i = 0; i < _ratings.size(); i++)
		{
			_ratings[i].Print(out);
			out << endl;
		}	
		out << endl;
	}
	
	string _name;
	vector<Rating> _ratings;
};

const int MAX_CARS = 5;
const int MAX_RATINGS = 4;

int main()
{
	Car myCars[MAX_CARS];
	string myCarNames[MAX_CARS] = { "Mustang", "Charger", "Supra", "GTO", "T-bird" };
	string myRatingNames[MAX_RATINGS] = { "Aero", "Engine", "Handling", "Grip" };


	// load everything up
	for (int i = 0; i < MAX_CARS; i++)
	{
		myCars[i].AddName(myCarNames[i]);
		
		for(int j = 0; j < MAX_RATINGS; j++)
			myCars[i].AddRating(myRatingNames[j]); 
	}
	
        // print out the car's ratings 
	for (int i = 0; i < MAX_CARS; i++)
		myCars[i].Print(cout);

    return 0;
}

Last edited on
Ok here is my code. I spent a good hour working on while loops so you can't go below 40 points, but with little success. Hope you find some value at least. However, if you have to choose, the code above mine looks a lot better and cleaner.

As for icethatjaw, are you saying I did not have to leave to pick up my girlfriend and stop at my parents earlier?

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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
const int MAX=2;


class Car
{
public:
	Car(){}
	Car(int a, int e, int h, int g, string s):aeor(a),eng(e), hand(h), grip(g), name(s){}

	void input();
	void print_car();
	void check_negative(int& n);

private:
	int aeor, eng, hand, grip;
	string name;
};


int main()
{
	Car cars[MAX];
	char choice;
	string filler;
	cout<<"Welcome to the friend car program.\n";
	for(int i=0;i<MAX;i++){
	
		do{
			if(i==0)filler=" st";
			if(i==1)filler=" nd";
			if(i==2)filler=" rd";
			if(i>=3)filler=" th";
			cout<<"Enter the "<<i+1<<filler<<" vehicle\n\n";

			cars[i].input();
			cout<<endl;
			cout<<"You have entered the following car\n";
			cars[i].print_car();
			cout<<"Is this information correct?(y/n)\n";
			cin>>choice;
			cin.ignore(1000,'\n');
		}while(choice=='n' || choice=='N');
	
	}
	cout<<"Car list is\n";
		
	cout<<"+++++++++++++++++++++++++++++++++++++++++++\n";
	for(int j=0;j<MAX;j++){
		cars[j].print_car();
		cout<<"-----------------------\n";
	}
	cout<<"+++++++++++++++++++++++++++++++++++++++++++\n";	
		
	_getch();
	return 0;
}
void Car::print_car()
{
	cout<<left<<setw(15)<<"Name: "<<name<<endl;
	cout<<left<<setw(15)<<"Aerodynamics: "<<aeor<<endl;
	cout<<left<<setw(15)<<"Engine: "<<eng<<endl;
	cout<<left<<setw(15)<<"Handling: "<<hand<<endl;
	cout<<left<<setw(15)<<"Grip: "<<grip<<endl;
}
void Car::check_negative(int& n){
	while(n<0){
		cout<<"Can't go below zero points, try again: ";
		cin>>n;
	}

}
void Car::input()
{
	int points=40, total;

	
		cout<<"Enter the name of the vehicle: ";
		getline(cin,name);
		while(name.length()>10){
			cout<<"Vehicle name too long, enter again: ";
			getline(cin,name);
		}
		
		cout<<"Enter points for Aerodynamics: ";
		cin>>aeor;
		check_negative(aeor);
		total=40-aeor;
		cout<<"\nPoints remaining: "<<total<<endl;	

		cout<<"Enter points for Engine: ";
		cin>>eng;
		check_negative(eng);
		total=total-eng;	
		cout<<"\nPoints remaining: "<<total<<endl;

		cout<<"Enter points for Handling: ";
		cin>>hand;
		check_negative(hand);
		total=total-hand;	
		cout<<"\nPoints remaining: "<<total<<endl;
			
		cout<<"Enter points for Grip: ";
		cin>>grip;
		check_negative(grip);
		total=total-grip;
		cout<<"\nPoints remaining: "<<total<<endl;

		cout<<"This vehicle has "<<total<<" points remaining.\n";
}
Topic archived. No new replies allowed.