Here is all my code so far.
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
|
#include <iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
// struct - this is a data type, a group of related variables
struct horse_struct
{
int acc;
int end;
int speed;
}
int performance=horses[t].acc+horses[t].end+horses[t].speed;
int variable=rand()%100+1;;
int winner=performance+variable;
int main()
{
// make an array (effectively a list) of type horse_struct.
// So, we have six "horses", each having a copy of the
// variables within horse_struct
horse_struct horses[6];
int winner;
// This is a basic for-loop, it starts at t=0, and each
// time it loops around it increases t by 1 (the t++ bit)
// until t<6 is no longer true. Then it exits the loop.
// Here, it will look at all 6 horses
for (int t = 0; t < 6; t++)
{
// cout the text name, the << means we can cout an extra
// piece of data - the "t" giving the horse number
cout << "Enter acceleration of horse "<< t << ": ";
// horses[t] means the horse at slot t of the array (e.g.
// horses[0] gives you the first horse. the ".acc" lets
// you set the associated variable in the horse_struct
cin >> horses[t].acc;
// As above, but for the other variables
cout << "Enter endurance of horse " << t << ": ";
cin >> horses[t].end;
cout << "Enter speed of horse " << t << ": ";
cin >> horses[t].speed;
cout << "The winner is:" << winner <<".";
}
return 0;
}
| |
I now get 7 errors on line 14 and one on line 16.
Here is what my compiler (Code:Blocks) says.
C:\Users\Steven\Documents\Code Blocks\Horse Racing Sim 2\main.cpp|14|error: two or more data types in declaration of 'performance'|
C:\Users\Steven\Documents\Code Blocks\Horse Racing Sim 2\main.cpp|14|error: 'horses' was not declared in this scope|
C:\Users\Steven\Documents\Code Blocks\Horse Racing Sim 2\main.cpp|14|error: 't' was not declared in this scope|
C:\Users\Steven\Documents\Code Blocks\Horse Racing Sim 2\main.cpp|14|error: 'horses' was not declared in this scope|
C:\Users\Steven\Documents\Code Blocks\Horse Racing Sim 2\main.cpp|14|error: 't' was not declared in this scope|
C:\Users\Steven\Documents\Code Blocks\Horse Racing Sim 2\main.cpp|14|error: 'horses' was not declared in this scope|
C:\Users\Steven\Documents\Code Blocks\Horse Racing Sim 2\main.cpp|14|error: 't' was not declared in this scope|
C:\Users\Steven\Documents\Code Blocks\Horse Racing Sim 2\main.cpp|16|error: 'performance' was not declared in this scope|
||=== Build finished: 8 errors, 0 warnings ===|
What am I doing wrong? I'm sure it's a dumb mistake but I don't know what.