i want this program show 2 arrays but i doesnt

<code>
#include <cstdlib>
#include <iostream>
#include <conio.h>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
#include <string.h>

using namespace std;


int main()
{
int middle; //this is the first array
int lenght;
int firststar;
int j;
int before;
int laststar;
int lenght2;
int i;
int firststar2;
int laststar2;
int trap;

cout<<"introduce the length"<<endl;
cin >>lenght; // then i introduce the length of the array
char array [lenght];
middle=lenght/2;
firststar=0;
array[firststar]='*'; // then the first char of array is a star
array[middle]='o'; // then the middle char is o
laststar=lenght-1;
array[laststar]='*'; // then the last one is the same, a star


for (j=0;j<lenght;j++) // through this for i want to make the program to check each char of the program
{
if (j!=firststar) // if it is a star it is a ' '
if (j!=middle)
if (j!=laststar)
array[j]=' ';
}
before=20;



lenght2=lenght;
char array2[lenght];
firststar2=0;
array2[firststar2]='*';
laststar2=lenght2-1;
array2[laststar2]='*'; // the same as up the first and last postition of program should show a star each of them

srand ( time(NULL) );
trap = rand() % lenght2;
while (trap); //instead of showing a ^ which should be atrap in the program i make
{
if (trap!=laststar2)
{
if (trap!=firststar2)
array2[trap]='^';
}
srand ( time(NULL) );
trap = rand() % lenght2;
}
for (i=0;i<lenght2;i++) // the same, if it is not star or trap the char should be ' '
{
if (i!=trap)
if (i!=firststar2)
if (i!=laststar2)
array2[i]=' ';
}

cout <<setw(before)<<array<<endl; // then it should show the arrays as i described










system ("PAUSE");
return 0;
}
// i dont understand why but my program shows the firsy array but i shows just the first one
</code>



why doesn't it SHOW BOTH ARRAYS AS I DESCRIBED?





while (trap); //instead of showing a ^ which should be atrap in the program i make

is an infinite loop due to the semicolon.
thank you...now it shows what it should. But it is not the whole program i havrt e to make. overall i have to make a game. o is the player here and ^ is a trap for it. if i press for example a it should go to the right the next row and if i press d it should go to the left. The only thing i don't know haw to do is how to make it delete the last line and show both: trap and player and appear a new row which has just the trap. please give me some suggestions for it. each one may be extremely useful for me.
For cursor manipulation you need a library such as curses (for Un*x).
hello.pls pls pls PIULITZA i need to know if you finished the program.
Last edited on
As i put so many questions its clear i didnt finish it
Topic archived. No new replies allowed.