**Cue usual spiel about being a noob and new to programming**
Here is the problem: Create an array of space ship objects and write a program that continually updates their positions until they all go off the screen. Assume that the size of the screen is 1024 pixels by 768pixels.
Build errors are at the bottom of the code...
I'm sure this is something obvious but I cannot figure out what I need to do here... Any hints or help would be appreciated.
Code:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
struct spaceShip
{
int x_coord;
int y_coord;
};
spaceShip ships[20];
spaceShip createShips (spaceShip ships[], int size)
{
for (int i = 0; i < size; i++)
{
ships[i].x_coord = rand() % 1024;
ships[i].y_coord = rand() % 768;
}
}
spaceShip updateLoc (spaceShip ships[], int size)
{
for (int i = 0; i < size; i++)
{
ships[i].x_coord = ships[i].x_coord + rand() % 100;
ships[i].y_coord = ships[i].y_coord + rand() % 50;
}
}
void displayTest (spaceShip ships[], int size)
{
cout << "{";
for (int i = 0; i < size; i++)
{
if ( i != 0 )
{
cout << "\n";
}
cout << ships[i].x_coord;
}
cout << "}";
}
spaceShip findHighest (spaceShip ships[], int size)
{
int highestValue = 0;
for (int i = 0; i < size; i++)
{
if (spaceShip ships[i] > highestValue)
{
highestValue = spaceShip ships[i];
}
}
return highestValue;
int main ()
{
srand(time(NULL));
createShips(ships, 20);
displayTest(ships, 20);
findHighest(ships, 20);
while (highestValue < 1024)
{
updateLoc(ships, 2)
findHighest(ships, 20);
}
cout << "All Ships have left the screen!\n";
}
C:\Users\Jake\Desktop\C++\Jumping_Into_C++\TBD\main.cpp||In function 'spaceShip createShips(spaceShip*, int)':|
C:\Users\Jake\Desktop\C++\Jumping_Into_C++\TBD\main.cpp|23|warning: no return statement in function returning non-void|
C:\Users\Jake\Desktop\C++\Jumping_Into_C++\TBD\main.cpp||In function 'spaceShip updateLoc(spaceShip*, int)':|
C:\Users\Jake\Desktop\C++\Jumping_Into_C++\TBD\main.cpp|31|warning: no return statement in function returning non-void|
C:\Users\Jake\Desktop\C++\Jumping_Into_C++\TBD\main.cpp||In function 'spaceShip findHighest(spaceShip*, int)':|
C:\Users\Jake\Desktop\C++\Jumping_Into_C++\TBD\main.cpp|50|error: expected primary-expression before 'ships'|
C:\Users\Jake\Desktop\C++\Jumping_Into_C++\TBD\main.cpp|50|error: expected ')' before 'ships'|
C:\Users\Jake\Desktop\C++\Jumping_Into_C++\TBD\main.cpp|52|error: expected primary-expression before 'ships'|
C:\Users\Jake\Desktop\C++\Jumping_Into_C++\TBD\main.cpp|52|error: expected ';' before 'ships'|
C:\Users\Jake\Desktop\C++\Jumping_Into_C++\TBD\main.cpp|55|error: conversion from 'int' to non-scalar type 'spaceShip' requested|
C:\Users\Jake\Desktop\C++\Jumping_Into_C++\TBD\main.cpp|58|error: a function-definition is not allowed here before '{' token|
C:\Users\Jake\Desktop\C++\Jumping_Into_C++\TBD\main.cpp|69|error: expected '}' at end of input|
||=== Build finished: 7 errors, 2 warnings ===|