Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C++
#include<stydio.h>
#include<conio.h>
#include<stdlib.h>
void main{
int i,j,noframes,x,x1,x1=10,x2;
clrscr();
for(i=0;i<200;i++)
rand();
noframes=rand()/200;
i=1;
j=1;
noframes=noframes/8;
printf("\n number of frames is %d"i);
getch();
while(noframes>0)
{
printf("\nsending frame %d",i);
srand(x1++)
x=rand()%10;
if(x%2==0)
{
for(x2=1;x2<2;x2++)
{
printf("waiting for %d seconds\n",x2);
sleep(x2);
}
printf("\nsending frame %d",i);
srand(x1++);
x=rand()%10;
}
printf("\nack for frame %d,i);
noframes-=1;
j++;
j++;
}
printf("\n end of stop and wait protocol");
getch();
}


What I have tried:

i try to convert code to pseudocode
Posted
Updated 16-Dec-20 4:20am
v3
Comments
F-ES Sitecore 7-Jun-20 13:18pm    
Pseudo code is subjective, there is no absolute answer. If you can't convert it to pseudo code then you probably don't understand what the code is doing, so start with understanding it and the rest will follow.
Greg Utas 7-Jun-20 13:51pm    
Even if it were properly formatted, that code would still be crap. That final printf is a clue, but I'm not sure I believe it. For one thing, j is a write-only variable.

1 solution

Here's something to get you started:
C++
1. for(i=0;i<200;i++)
2. rand();
3. noframes=rand()/200;

Using the above lines
1. FOR i from 0 to 199
   DO
2.    Get a random number and throw it away
3.    Get a random number
      Divide it by 200
      Store the result in the noframes variable
// etc.
 
Share this answer
 
Comments
Member 14856142 9-Jun-20 21:01pm    
Can you write the full answer, please?
Maciej Los 10-Jun-20 2:34am    
Isn't that enough?
Richard MacCutchan 10-Jun-20 2:45am    
Sorry, no; we are not here to do your work for you. I have given you a starting point to help you to understand what is required. The rest is up to you.
Maciej Los 10-Jun-20 2:33am    
5ed!
Richard MacCutchan 10-Jun-20 2:46am    
Thanks, do I get another 5 if I write it all? :))

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900