|
And what does that tell you?
|
|
|
|
|
To tell the truth, I don't understand.
|
|
|
|
|
Then maybe you should forget this program and start learning C and how it operates in better detail. You cannot become a developer by copying other people's code and guesswork.
|
|
|
|
|
You might get out of bound array accesses when step is always >= 0.63:
total=n*7;
num=(int *) malloc(total*sizeof(int));
do
{
j=0;
for(i=0; i<=n; i++)
{
if (step >= 0.03)
{
j=j+7;
}
}
}
while (!kbhit()); You have to change the for loop to
for(i=0; i<n; i++) I also don't understand why you are only updating when step is large enough. If that does not happen, balls at the end of the array will be updated less often than the initial ones.
You are checking if the new ball position is outside and inverts the direction if so but are still drawing the ball when outside. A better solution might be drawing it at the border (here for x):
if (num[j]+num[j+4]>=getmaxx() || num[j]-num[j+4]<=0)
{
num[j+5] *= -1;
if (num[j]+num[j+4] > getmaxx())
num[j] = getmaxx() - num[j+4];
if (num[j]-num[j+4] < 0)
num[j] = num[j+4];
}
Finally it might not work as expected because you have up to 7 balls and did not handle overlapping ones. I guess you want to detect also ball collisions which would result in no overlapping. But that is also not handled by your code.
|
|
|
|
|
Well, it didn't work and yes I also want to handle overlapping balls and make them bounce together and change direction. But, I don't know how. However, I don't have up to 7 balls. I actually use 3, but each of them has 7 data (color, position, speed etc.). That's why I use i at the for loop to count the number of loops (each ball). Then I use j to go to the desired data of each ball. All the data is being inserted to the program from a .txt file as you can see. It might seem stupid that I don't understand some thing. However, I am a beginner and I am trying to learn. So, please help me and be patient. I really appreciate your help.
|
|
|
|
|
Sorry, I missed the number of balls.
But my other notes are still valid (out of bound array access and why not updating with small steps). For timing purposes (slower movement), wait outside the for loop.
I suggest to start with one ball to implement and check the border bouncing. To be realistic, the new directions should be calculated according to the collision angle.
Then proceed with two balls to make it simpler. For collison detection you need another loop (runing from currently processed ball index + 1 to number of balls) to check for collisions like with the borders. Upon a collision you have to set the collision position as new position for both balls and adjust the directions (which requires a flag / state that the other ball has been already processed within the current loop execution). Again, the new directions should be calculated according to the collision angles.
To check the code, you can suppress the drawing and print out the positions and changings instead. Or write them to a text file so that you can inspect it later. For testing it might be also helpful to stop after each step and continue after a key press. So you can check your calculations.
|
|
|
|
|
I have already made it with one ball and I tried to continue with two, three etc. However, I still do something wrong with more than one balls and I can't understand what. I have been working on this for almost a month and I have tried everything. I also searched the internet and asked at other forums too, but still nothing. I only managed to make it with one ball. I understand what you say and that's what I am thinking too, but I can't put it inside code and make it run correctly.
|
|
|
|
|
Your posted code does not check for ball to ball collisions. You have to implement it. There should be examples in the net for the algorithms.
|
|
|
|
|
Are you trying to recreate a 30-years old xonix game?
|
|
|
|
|
For your next assignment, extend your program to work in three dimensions and use OpenGL to display the balls. For bonus credit, display the bounding cube with translucent walls. In other words, partially transparent but not totally.
Good luck.
|
|
|
|
|
2 errors is coming can anyone help me
|
|
|
|
|
Here are some possibilities: LMGTFY[^]
<sig notetoself="think of a better signature">
<first>Jim</first> <last>Meadors</last>
</sig>
|
|
|
|
|
nithiin_sai wrote: 2 errors is coming can anyone help me
Maybe...
But only if you'll show your code and exact error messages.
|
|
|
|
|
It could be worse, it could be raining.
|
|
|
|
|
nithiin_sai wrote: ...can anyone help me
At this point, no.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
|
You should post the question in the forum at the end of the article, so the person who created the code can answer.
|
|
|
|
|
|
Thank you ! This could be a good track to follow ... until then, I am facing to far more easy problem:
How To Hide A Window in TaskBar[^]
modified 18-Jan-18 7:31am.
|
|
|
|
|
The rules for that are spelled out in detail from Microsoft
The Taskbar[^]
SetWindowLong(yourHWND, GWL_EXSTYLE, GetWindowLong(yourHWND, GWL_EXSTYLE) & ~(WS_EX_APPWINDOW | WS_EX_TOOLWINDOW));
Straight after you create the window grab the handle and change the style flags and it will stop it being displayed.
In vino veritas
|
|
|
|
|
It is easy and can be easily solved by just reading the article:
typedef ITaskbarList *LPITaskbarList
|
|
|
|
|
I have tried this the below code but the compiler is showing logic error. I am unable to find my error.
And please tell me what is the right logic.
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
int find(int name);
int check(int temp[], int i);
void del(int name);
int repetetion(int temp[] , int name);
int indexing(int temp[]);
int m[3], r[3], l[3];
int mp=0, rp=0, lp=3 ;
int main()
{
int i=0;
int temp=1, name;
char position, answer;
while(i < 4)
{
l[i] = 4-i;
m[i] = 0;
r[i] = 0;
}
printf("\nWelcome to the towers of hanoi. . . \n\n");
while((r[0] != 4 && r[1] != 3 && r[2] != 2 && r[3] != 1) && toupper(answer) == 'Y')
{
printf("\nEnter the block name:\n");
scanf("%d", &name);
find(name);
while(find(name) == 1){
printf("This block cannot be moved! Please chose again. . .\n");
scanf("%d", &name);
find(name);
}
printf("\n\nEnter the position you want to move it in..\n");
scanf("%1s", &position);
while(temp=1)
{
if(toupper(position)=='M'){
if(find(name)==0 && (temp=repetetion(m, name))==0){ del(name); m[mp] = name; mp++; continue;
}
}
else if(toupper(position) == 'L'){
if(find(name)==0 && (temp =repetetion(l, name))==0){
del(name);
l[lp] = name;
lp++;
continue;
}
}
else if(toupper(position) == 'R'){
if(find(name)==0 && (temp = repetetion(r, name))==0){
del(name);
r[rp] = name;
rp++;
continue;
}
}
printf("Invalid entry! Please enter again. . ."); scanf("%1s", &position);
}
if( r[0] == 4 && r[1] == 3 && r[2] == 2 && r[3] == 1)
{
printf("\n\nYou have solved the HANOI TOWER PUZZLE. . .");
printf("\n\nWant to play again? (Y/N) ");
scanf("%1s", &answer);
}
}
printf("\t\tTHANK YOU !");
return 0;
}
int find(int name)
{
int i, temp;
for(i=0; i<4; i++)
{
if(m[i]==name){
temp = check(m, i); }
else if(l[i]==name){
temp = check(l, i);
}
else if(r[i]==name){
temp = check(r, i);
}
}
return (temp);
}
int check(int temp[], int i)
{
if(i != indexing(temp))
return(1) ;
else if(i == indexing(temp))
return(0) ;
}
int indexing(int temp[])
{
int count=0;
while(temp[count]!= 0)
{
count++;
}
return(count) ;
}
int repetetion(int temp[] , int name)
{
int i, flag;
for(i=0; i<4; i++)
{
if(temp[i] == name)
{
flag = 1;
break;
}
else
{
flag = 0;
}
}
return(flag);
}
void del(int name)
{
int i;
for(i=0; i<4; i++)
{
if(m[i]==name){
m[i] = 0;
mp--;
}
else if(l[i]==name){
l[i] = 0;
lp--;
}
else if(r[i]==name){
r[i] = 0;
rp--;
}
}
return ;
}
Thank you
|
|
|
|
|
If you got compiler errors and warnings, inspect them or add them to your question so that we know them. They contain the line number where the error occured. Inspect that line and the previous one(s) (some errors are sourced on previous lines and detected later). Read the error message. If you do not understand them, do some web research first.
However, there is one big beginner's mistake in your code:
The size of the arrays and the access to the array elements. With C/C++, arrays are accessed by zero based indexes. So the allowed indexes for a size of three are 0, 1, and 2. But your code uses also the index 3. As a result, your code will never work as expected or even crash.
So change the array sizes to
int m[4], r[4], l[4]; before handling any other errors.
|
|
|
|
|
the compiler just keeps on running , i.e. just the cursor appears and nothing else
|
|
|
|
|
That is not the compiler, but your program when executed after compiling.
The solution to that problem is provided below by Richard.
But my answer is still valid and important. And there might be more errors.
|
|
|
|