The code is supposed to read in 20 integers(I changed it to 5 to begin with just to make the trial&error process smoother)
After 20 integers are stored in array "number" it should ask for a lower and upper limit. The numbers that are between these two values lets say
20 is lower and 40 is upper..then 21,22,23,24...39,40 should be the numbers in between, now what I want is for the program to display what numbers that DO NOT exist between these two limits.
What I mean is the numbers i typed in from the start..like if the limits are 16 to 19 and I only typed in 17 and all my other choices were either above or under the limits.
So it should display 16,18 and 19 as missing.
Like "Hey you got 17 right but 16,18 and 19 are missing!"
And the script should stop accepting new limits after you've typed in 0 as the lower limit.
The correct output of the program should be:
-------------------------------------------------------------------------
Type in 20 integers:
4 7 8 9 2 14 15 56 3 7 23 24 25 27 29 32 31 23 16 26
Upper limit: 14
Lower limit: 16
The number 14 up to 16 are all present.
Lower limit: 24
Upper limit: 32
Between 24 and 33 the following numbers are missing: 28, 30, 33.
Lower limit: 0
Game over..
--------------------------------------------------------------------------
I'v posted my code and it works fine if you just want to display what numbers that are between lowerlimit and upperlimit.
But I need to list whatever numbers that aren't present aswell :(
Could anyone help out here whatever I'm just messing my loops up, I'd really appreciate if you'd be thoroughal since I'm very new with C I'v been taking this course for 2 weeks.
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
int main(void)
{
int i,allnumbers[20],lowerlimit,upperlimit;
printf("Type in 20 integers: ");
for(j=1;j<=20;j++)
{
scanf("%d",&allnumbers[j]);
}
while(!(lowerlimit==0))
{
printf("\n");
printf("Lowerlimit: ");
scanf("%d",&lowerlimit);
if(lowerlimit==0)break;
printf("upperlimit: ");
scanf("%d",&upperlimit);
for(i=1;i<=20;i++)
{
if(allnumbers[i]>=lowerlimit && allnumbers[i]<=upperlimit)
{
printf("%d ",allnumbers[i]);
}
}
}
printf("Game over!");
getch();
}


Sign In
Create Account

Back to top









