Functions

I wrote the below code last week and need to change it to Create functions based on your existing source code (ex. GetCar, CreateCar, CalculateLapTime) which take in the appropriate parameters and give the correct output. Use pointers where applicable.
Move validation code into functions where appropriate, and throw an exception if the input does not match your validation rules. Handle the exceptions accordingly in your main function, and output the error message to the console.

I have no idea how...

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
  Put the code you need help with here.
#include <iostream>
#include <string>
using namespace std;


struct Car
{
	std::string color;
	std::string driver_name;
	int number;
	int t_minutes;
	int t_seconds;
};


int main()
{
	const int SIZE = 3;
	Car cars[SIZE];
	// fill up the array with Cars
	for (int i = 0; i < SIZE; i++)
	{
		std::cout << "Who is the driver for car " << i + 1 << "? ";
		std::getline(std::cin, cars[i].driver_name);
		std::cout << "What is the color for car " << i + 1 << "? ";
		std::getline(std::cin, cars[i].color);
		std::cout << "What is car number for car " << i + 1 << "? ";
		std::cin >> cars[i].number;
		std::cout << "What was the laptime for car " << i + 1 << "? ";
		std::cin >> cars[i].t_minutes >> cars[i].t_seconds;
		std::cin.ignore(1000, '\n');
		std::cout << "\n";
	}

	// print out info
	for (int i = 0; i < SIZE; i++)
	{
		std::cout << cars[i].color << std::endl;
		std::cout << cars[i].number << std::endl;
		std::cout << cars[i].t_minutes << ":" << cars[i].t_seconds << std::endl;
		std::cout << "\n";
	}

	

		return 0;
}
Dude, how many times are you going to post the same question?
Your previous post (with the same question) is in fact at the top of the list at the moment.....

http://www.cplusplus.com/forum/beginner/200103/
Until I understand what to do. I am still confused and figured you moved on.
closed account (E0p9LyTq)
Keep posting NEW threads with the same question is only going to make people IGNORE you.

Stay with your original thread, those who choose to help you will tell you when they are done. You need to be patient, after all you are getting help for FREE.
I get that. Thought it may help speed the process up if it were in different places. I have gotten great help on here before and today I guess it just ended. Was not trying to cause a riot.
Topic archived. No new replies allowed.