-
Program not working
Hi Guys!
Im new to c++ but have made a few programs. I am currently making a memory testing game. it was all working well untill i started using an array to generate random numbers. if the code is too dificult to understand i'll anotate it but other than that can anyone help me?
here is the code:
Code:
#include <cstdlib>
#include <iostream>
#include <dos.h>
#include <windows.h>
#include <stdlib.h>
#include <conio.h>
using namespace std;
int main()
{
int numberarray[20];
int numberarrayplace;
cout<<"Welcome to Dave's memory lab! \n";
cout<<"Here we will carry out a test: \n";
cout<<"Remember the numbers!";
cout<<"You will be given 20 numbers from 0 to 100 and you have 30 seconds to memorize them \n";
cout<<"Then you will be tested... \n";
Sleep(1000);
cout<<"3 \n";
Sleep(1000);
cout<<"2 \n";
Sleep(1000);
cout<<"1 \n";
Sleep(1000);
system("cls");
numberarray = 1;
for ( 1 == 1 ) {
numberarray[numberarrayplace] = rand(100);
cout<< numberarray[numberarrayplace] << " ";
}
cout<<"Here are your numbers \n";
Sleep(30000);
cout<<"Times up! \n";
}
it's not finnished yet but im getting these errors:
C:\Dev-Cpp\Projects\Fun Projects\Memory Chalenge\main.cpp In function `int main()':
29 C:\Dev-Cpp\Projects\Fun Projects\Memory Chalenge\main.cpp incompatible types in assignment of `int' to `int[20]'
30 C:\Dev-Cpp\Projects\Fun Projects\Memory Chalenge\main.cpp expected `;' before ')' token
35 C:\Dev-Cpp\Projects\Fun Projects\Memory Chalenge\main.cpp expected `)' before ';' token
C:\Dev-Cpp\Projects\Fun Projects\Memory Chalenge\Makefile.win [Build Error] [main.o] Error 1
i apreciate your help.
Gillypie :)
-
Code:
for ( 1 == 1 ) {
numberarray[numberarrayplace] = rand(100);
for loops have the form
Code:
for(initialization; condition; increment)
All three sections can be empty, but you at least need those two semicolons.
In addition, rand() takes no parameters. If you want a random number between 0 and 99 inclusive, use
Code:
#include <dos.h>
#include <windows.h>
#include <stdlib.h>
#include <conio.h>
dos.h and conio.h are non-standard, and you're using nothing from them, so why include them? (Sleep() is from windows.h, however. It's also non-standard.)
stdlib.h is the same as cstdlib if you have using namespace std. Only include one of them. I suggest cstdlib.
-
ok so whats the syntax for adding the colons to the for loop.
sorry to sound stupid.
-
You want the loop to execute 20 times, to print 20 numbers, right?
This is the normal syntax of a for loop for that sort of thing.
Code:
for(int x = 0; x < 20; x ++)
I think that maybe you should read some tutorials about for loops. http://www.cprogramming.com/tutorial/lesson3.html
-
thnx but ive decided to use a do while loop for the purposes. youve helped me alot though i understand loops properly now. thnx!
:)