took me a long time to figure out how to make this program going from right to left, to left to right. I now need to figure out how to make it hit the screen edge and start heading back in the next direction and bounce.
please dont just "tell" me the answer but if you can give me some hints id appreciate it.
#include <iostream>
#include <windows.h>
//Taylor Mon
usingnamespace std;
int main()
{
int pos;
int spaces;
pos = 77;//tells program to start at position 77
while (pos<78)
{
spaces = 0;
while (spaces<pos)
{
cout << " ";//displays empty space
spaces++;
}
cout << "A " << "\r";
pos--;
Sleep(75);//speeds up the program
}
return 0;
}
Hello there again. First, it seems you have an infinite loop there. pos = 77 and your loop will keep going while pos is < 78(it always is).
After you fix that, I guess the easiest way would be create another loop to go the direction you want. 77 to ?, ? to ?? ? I hope I didn't help too much this time.
thanks again im sorry i have not been checking the forum over the weekend.
this is what i wrote in class today, its going back and forth forever, which is what i need but its not going to the end of page just back and forth... ?
That's not I had in mind. You could make 2 while statements, one going from, let's say, right to left and another going from left to right. And when you want some code to repeat itself all you have to do is put something around it.
You could even ask the user how many times you want it to loop and use the answer to create the new statement.
1 2 3 4 5 6 7
insert something here
{
while1 ( 78 to 0 )
while2 ( ? to ?? )
}
The answer I give here, may help you with your program. The word will go back and forth on the screen, but the program also rotates the word. Just leave that part out if you don't need it. Hope this helped..
thanks everybody, im nt going to ope the link tho @whitenite. I appreciate it but i figured it out with only using one while statement...
it works anyways and ive handed it in.
again everyone thanks for all the tips your wonderfull !
@lumpkin , the prof had the sleep set at 300 and it took an eternity for the character to move to one side to the other, when i set it at 75 it moved the character left and right alot faster.