new to programming

hey everybody I'm new to programming and I need help knowing which commands to type so that I can get the results that I need. This is for a school assignment yet I am not trying to obtain the answer or the code from anyone, I want to learn but since I am new I do not know what to do or how to do it, I have read and read but still have trouble knowing what exactly to use in order to get the results that I need.

I know the structure of the program starts like this

#include <iostream>
using namespace std;

int main()

{
return 0;
}

so I need to create a program for a three car race that calculates the output of the three car positions for a two lap race and a three lap race, using user input for all three cars lap times, and using variables for storing the data for each. the outputs I need are:
-user inputs
-car number
-color of car
-race time

what I need to know which commands or word to type so that I can get the results that I am looking for. I have watched some videos also and I see that the use int for the variables, in this case what would those variables would be,
like for car 1 I have color red, driver A, lap time 1MM:10SS
car 2 I have color blue, driver B, lap time 1MM:20SS
and car 3 I have color green, driver C, time 1MM:30SS

So I would put within the brackets

int car 1
car 1 = color blue, driver a, lap time 1MM:10SS

int car 2
car 2 = color red, driver b, lap time 1MM:20SS

int car 3
car 3 = color green, driver C, lap time 1MM:30SS

correct?

and this is where I'm stuck do not know what to do next
It is hard to tell what exactly you need.
First of all, I would recommend studying C++ at least at a basic level before attempting something like this.

If you really want me to show you, you probably won't understand it.
I understand some of it and I have read it just does not click to me as to what to put, is what I wrote at least correct? or am in not even close
Ok, do you know what a function and a class are?
If so, write a little bit of the program and I'll help you find that answer yourself.
wouldn't the function be what I wrote? what is expected for the program to execute right?

so it would be like

int main()
{
int car1;
cout <<"enter car 1 color:">>;
cin >> red;
cout<<"enter car1 driver:">>;
cin>> A;
cout<<"enter car1 lap time:">>;
cin>> 1MM:10SS;

int car2;
cout <<"enter car2 color:">>;
cin >> blue;
cout<<"enter car2 driver:">>;
cin>> B;
cout<<"enter car2 lap time:">>;
cin>> 1MM:20SS;

int car3;
cout<<"enter car 3 color:">>;
cin >> green;
cout<<"enter car3 driver:">>;
cin>> C;
cout<<"enter car1 lap time:">>;
cin>> 1MM:30SS;

am I in the right path?
Please use code tags like so:
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
int main()
{
int car1;
cout <<"enter car 1 color:">>;
cin >> red;
cout<<"enter car1 driver:">>;
cin>> A;
cout<<"enter car1 lap time:">>;
cin>> 1MM:10SS;

int car2;
cout <<"enter car2 color:">>;
cin >> blue;
cout<<"enter car2 driver:">>;
cin>> B;
cout<<"enter car2 lap time:">>;
cin>> 1MM:20SS;

int car3;
cout<<"enter car 3 color:">>;
cin >> green;
cout<<"enter car3 driver:">>;
cin>> C;
cout<<"enter car1 lap time:">>;
cin>> 1MM:30SS;


Ok, it seems that you know how to use functions. Yes, you're on the right path but you have to tell me more about your problem.
Do you need all the data about the race to be input or is some of it calculated?
What do you do with the data once you have it?
so what I need to do is calculate the output for the three car positions in a two lap race and in a three lap race using the user inputs for al three cars lap times and variables for storing the data for each car. I need to print the output for user to see who won each race based on the user inputs, car number, color of car, and race time. So the user inputs are what I wrote correct? how would I calculate or determine who wins? this is where I am stuck I do not know what to do next?
OK, first I would create a variable for each car. It will be the time it took to complete the race. You can determine who won by selecting the smallest time.
This is where object-oriented programming comes in--you can create a car class and make multiple instances of it to represent all the different cars. Each can have its own variable for the race length, speed, color, and anything else.
Are you comfortable working with classes?
I don't think I am there yet but I can try. how would that be? and variables for each car would be like

int x;
x=car1;

and so on?
OK,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Class Car
{
string color;
int laptimes[3];
public:
public Car(string Color)
{
    color = Color;
}
string GetColor()
{
    return color;
}
void SetLapTime(int lap, int time)
{
    laptimes[lap] = time;
}
}


This is a very simple class that lets you think in terms of real-world objects.
Do you understand the class I wrote?
Last edited on
I understand what that means just not where would I put that? so I would replace what I wrote for this for each car? then where would I declare the values, like how would the user know what to type or the program to run? I don't think I'm this far yet, I really appreciate all your help, sorry if I seem too dumb
No, you're just trying to learn. Everyone has to do it at some point!

Think of the class Car as an actual object. The variables inside it(the string and the int) are attributes--color and time per lap.
The functions inside of the class are used to make the Car do something--like move or give you its color.
The user of the class can call any of the functions"making the car do something" by using Car.doDomething() where doSomething is the name of the function you're calling in the Car.
For example:
1
2
3
4
5
6
7
8
9
10
11
12
Car cars[3];//Create an array of three cars
for(int i = 1; i < 4; i++)
{
    cout << "Enter the color of car #" << i << endl;
    string carcolor = "";
    cin >> carcolor;
    cars[i - 1].color = carcolor;
    cout << "Enter the lap time for car #" << i << endl;
    int laptime = 0;
    cin >> laptime;
    cars[i - 1].SetLapTime(i - 1, laptime);
}


And you just set all the colors of three cars and their lap times.

Make sense?
ok so it would be like this then :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include<iostream>
#include<string>

int main()
{

Car cars[3];//Create an array of three cars
for(int i = 1; i < 4; i++)
{
    cout << "Enter the color of car #" << i << endl;
    string carcolor = "Red,Blue,Green";
    cin >> carcolor;
    cars[i - 1].color = carcolor;
    cout << "Enter the lap time for car #" << i << endl;
    int laptime = 0;
    cin >> laptime;
    cars[i - 1].SetLapTime(i - 1, laptime);
}
}
Yes.
You're on the right track now.
Just try to finish it--you'll learn how to use classes faster if you get a good book or look up some articles.

Good luck!
Topic archived. No new replies allowed.