Click here to Skip to main content
15,887,175 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Problem with multiple bouncing balls program in C Pin
Richard MacCutchan19-Jan-18 0:36
mveRichard MacCutchan19-Jan-18 0:36 
AnswerRe: Problem with multiple bouncing balls program in C Pin
Member 1363226319-Jan-18 0:59
Member 1363226319-Jan-18 0:59 
GeneralRe: Problem with multiple bouncing balls program in C Pin
Richard MacCutchan19-Jan-18 1:05
mveRichard MacCutchan19-Jan-18 1:05 
GeneralRe: Problem with multiple bouncing balls program in C Pin
Member 1363226319-Jan-18 1:22
Member 1363226319-Jan-18 1:22 
GeneralRe: Problem with multiple bouncing balls program in C Pin
Richard MacCutchan19-Jan-18 1:23
mveRichard MacCutchan19-Jan-18 1:23 
GeneralRe: Problem with multiple bouncing balls program in C Pin
Member 1363226319-Jan-18 1:54
Member 1363226319-Jan-18 1:54 
GeneralRe: Problem with multiple bouncing balls program in C Pin
Richard MacCutchan19-Jan-18 2:51
mveRichard MacCutchan19-Jan-18 2:51 
AnswerRe: Problem with multiple bouncing balls program in C Pin
Jochen Arndt19-Jan-18 1:07
professionalJochen Arndt19-Jan-18 1:07 
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)
        {
            // Possible out of bound accesses here (j >= total)
            // ...
            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.
GeneralRe: Problem with multiple bouncing balls program in C Pin
Member 1363226319-Jan-18 1:53
Member 1363226319-Jan-18 1:53 
GeneralRe: Problem with multiple bouncing balls program in C Pin
Jochen Arndt19-Jan-18 2:21
professionalJochen Arndt19-Jan-18 2:21 
GeneralRe: Problem with multiple bouncing balls program in C Pin
Member 1363226319-Jan-18 2:30
Member 1363226319-Jan-18 2:30 
GeneralRe: Problem with multiple bouncing balls program in C Pin
Jochen Arndt19-Jan-18 2:56
professionalJochen Arndt19-Jan-18 2:56 
AnswerRe: Problem with multiple bouncing balls program in C Pin
Victor Nijegorodov19-Jan-18 21:21
Victor Nijegorodov19-Jan-18 21:21 
AnswerRe: Problem with multiple bouncing balls program in C Pin
Rick York24-Jan-18 7:17
mveRick York24-Jan-18 7:17 
Questionconvert feet and inches to centimeters Pin
nithiin_sai18-Jan-18 14:42
nithiin_sai18-Jan-18 14:42 
SuggestionRe: convert feet and inches to centimeters Pin
Jim Meadors18-Jan-18 15:49
Jim Meadors18-Jan-18 15:49 
AnswerRe: convert feet and inches to centimeters Pin
Victor Nijegorodov18-Jan-18 20:38
Victor Nijegorodov18-Jan-18 20:38 
AnswerRe: convert feet and inches to centimeters Pin
CPallini18-Jan-18 21:47
mveCPallini18-Jan-18 21:47 
AnswerRe: convert feet and inches to centimeters Pin
David Crow19-Jan-18 3:16
David Crow19-Jan-18 3:16 
QuestionStart app without taskbar icon Pin
_Flaviu17-Jan-18 1:56
_Flaviu17-Jan-18 1:56 
AnswerRe: Start app without taskbar icon Pin
Richard MacCutchan17-Jan-18 2:11
mveRichard MacCutchan17-Jan-18 2:11 
AnswerRe: Start app without taskbar icon Pin
Jochen Arndt17-Jan-18 2:20
professionalJochen Arndt17-Jan-18 2:20 
GeneralRe: Start app without taskbar icon Pin
_Flaviu18-Jan-18 1:09
_Flaviu18-Jan-18 1:09 
GeneralRe: Start app without taskbar icon Pin
leon de boer18-Jan-18 1:40
leon de boer18-Jan-18 1:40 
GeneralRe: Start app without taskbar icon Pin
Jochen Arndt18-Jan-18 2:07
professionalJochen Arndt18-Jan-18 2:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.