HELP PLEASE!

I wrote this code last week and it is not entirely correct. I have to add 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.
To it for this week. I need help badly. I am lost. Code below from last week......

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
#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";
	}

			cout << endl << "Fastests: " << endl;
	if (s1 <= s2 && s1 <= s3)
		cout << driver1 << " " << color1 << " " << number1 << " " << s1 << "seconds" << endl;
	if (s2 <= s1 && s2 <= s3)
		cout << driver2 << " " << color2 << " " << number2 << " " << s2 << "seconds" << endl;
	if (s3 <= s2 && s3 <= s1)
		cout << driver3 << " " << color3 << " " << number3 << " " << s3 << "seconds" << endl;
	else cout << "Error invalid entry" <<

	return 0;
}
So what exactly is your problem?
What have you tried?
I can't fix it and I do not know how to accomplish the task of adding the new requirements to it.
Imagine something like this.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/** \brief A function that creates a new Car object with random values for the minutes and seconds
 */
Car CreateCar(int number)
{
	// last weeks magic code goes here
}

...

int main()
{
...
	// fill up the array with Cars
	for (int i = 0; i < SIZE; i++)
	{
		cars[i] = Create(i);
	}
...
}


B.t.w. Radboud?
I don't understand. Did I say Radboud? lol I have no idea what that is. Would that be how I fix the array currently there or is that part of the new stuff I need to incorporate? Can you break it down for me please...
Would I keep all of last weeks code then? And start this weeks with the example? Would that be the whole thing? I really appreciate you taking the time out to help me, I am in over my head.
ok I think that is a function, now will I need multiple functions to make it run properly? I do not believe my error message was put in properly, any ideas how to fix?
I think they want you to look at the code you created last week and find that it consists of different sections. One of those sections is a loop where you create the Car objects, another is where you calculate lap times and so on.

If I were you I would create a new file, with a main function and the prescribed functions and subsequently try to find the corresponding section in last weeks code. One you found it, you copy it into the new function.
Finally, you update your main function to use the functions.

For example
1
2
3
4
5
6
7
8
9
10
int main()
{
	for (int i=0; i<10; i++)
	{
		std::string name;
		std::cout << "what is your name?\n";
		std::cin >> name;
		std::cout << "hello, " << name << "\n";
	}
}



might become
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
std::string askForName()
{
	std::string name;
	std::cout << "what is your name?\n";
	std::cin >> name;
	return name;
}
void printGreeting(std::string name)
{
	std::cout << "hello, " << name << "\n";
}

int main()
{
	for (int i=0; i<10; i++)
	{
		std::string name;
		name = askForName();
		printGreeting(name );
	}
}


which in turn might become
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
std::string askForName()
{
	std::string name;
	std::cout << "what is your name?\n";
	std::cin >> name;
	return name;
}
void printGreeting(std::string name)
{
	std::cout << "hello, " << name << "\n";
}

int main()
{
	for (int i=0; i<10; i++)
	{
		printGreeting(askForName());
	}
}


And no, I was asking, Radboud is a university where they happen to have very similar assignments.
You are correct, your compiler probably says something like expected ; before return.
The problem is that you never finished the this statement:

"else cout << "Error invalid entry" <<"

probably you forgot an endl; or "\n";
I see and yes when I deleted the last paragraph it compiled with no errors from last week. My whole visual studio was down so I could not test before I submitted which was a complete disaster. Thank you for your help.
Topic archived. No new replies allowed.