|
||||||
| C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Hi!
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. Code:
#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();
}
|
| Sponsored Links |
|
|
|
|||
|
Quote:
Like if the limit was 14 to 18 and i type in 20 integers and only one of them are between 14 and 18 lets say 15.. Now there's 14,16,17 and 18 missing and I'd like my program to print that out like the "correct output" above. thanks for the reply ! |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Noob Questtion.... | teckmonkey | C and C++ | 2 | 07-27-2007 11:51 PM |
| Question about String handling... | Spitfire | Java Help | 2 | 06-08-2007 06:17 PM |
| web dev noob question | jub jub jedi | General Programming | 1 | 03-26-2007 07:41 AM |
| Best Linux for a noob... | PC101 | General Programming | 14 | 09-22-2006 10:21 AM |
| WingedPanther | ........ | 2753.6 |
| Xav | ........ | 2704 |
| Brandon W | ........ | 1702.32 |
| John | ........ | 1207.73 |
| marwex89 | ........ | 1175.24 |
| morefood2001 | ........ | 966.05 |
| dcs | ........ | 655.75 |
| Steve.L | ........ | 475.59 |
| orjan | ........ | 418.58 |
| Aereshaa | ........ | 383.54 |