Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

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.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-24-2007, 09:30 AM
Nousferatou Nousferatou is offline
Newbie
 
Join Date: Sep 2007
Posts: 7
Rep Power: 0
Nousferatou is on a distinguished road
Default Noob C question

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();                
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 09-24-2007, 09:41 AM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,654
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

If you want to make a list of the numbers that aren't between the upper- and lower-limit, you should simple reverse the if-statement, you're using for listing the numbers that are between.
Code:
if(allnumbers[i]<lowerlimit && allnumbers[i]>upperlimit)
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 09-24-2007, 09:51 AM
Nousferatou Nousferatou is offline
Newbie
 
Join Date: Sep 2007
Posts: 7
Rep Power: 0
Nousferatou is on a distinguished road
Default

Quote:
Originally Posted by v0id View Post
If you want to make a list of the numbers that aren't between the upper- and lower-limit, you should simple reverse the if-statement, you're using for listing the numbers that are between.
Code:
if(allnumbers[i]<lowerlimit && allnumbers[i]>upperlimit)
Nah I guess I was unclear I want to know how to print the numbers that are missing between the lower & upper limit.
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 !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 09-24-2007, 10:45 AM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,654
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

Oh, in that way.
Take a look at this code:
Code:
#include <stdio.h>
#include <stdlib.h>

int main()
{ 
    int i, j;
	int allnumbers[20];
	int lowerlimit;
	int upperlimit;
	int result;
    
    printf("Type in 20 integers: ");
    for(i = 0; i < 20; i++)
        scanf("%d", &allnumbers[i]);
    
    while(lowerlimit != 0)
    {
		printf("\n");
		
        printf("Lowerlimit: ");
        scanf("%d", &lowerlimit);
        
        if(lowerlimit == 0)
			break;
		
		printf("upperlimit: ");
        scanf("%d", &upperlimit);
        
        printf("\n");
        printf("These are the numbers between %d and %d, you wrote:\n ", lowerlimit, upperlimit);  
        for(i = 0; i < 20; i++)
            if(allnumbers[i] >= lowerlimit && allnumbers[i] <= upperlimit)
                printf("%d ", allnumbers[i]);
        
        printf("\n");
        printf("These are the numbers between %d and %d, you didn't wrote:\n ", lowerlimit, upperlimit);
		for(j = lowerlimit; j <= upperlimit; j++)
		{
			result = 0;
			for(i = 0; i < 20; i++)
			{
				if(allnumbers[i] >= lowerlimit && allnumbers[i] <= upperlimit)
					if(allnumbers[i] == j)
						result = 1;
			}
			
			if(result == 0)
				printf("%d ", j);
		}
	                
		printf("\n");
    }
    
    printf("\n");
    printf("Game over!\n");
                               
    return 0;
}
This is how my output looks like:
Code:
Type in 20 integers: 4 7 8 9 2 14 15 56 3 7 23 24 25 27 29 32 31 23 16 26

Lowerlimit: 14
upperlimit: 16

These are the numbers between 14 and 16, you wrote:
 14 15 16
These are the numbers between 14 and 16, you didn't wrote:


Lowerlimit: 1
upperlimit: 40

These are the numbers between 1 and 40, you wrote:
 4 7 8 9 2 14 15 3 7 23 24 25 27 29 32 31 23 16 26
These are the numbers between 1 and 40, you didn't wrote:
 1 5 6 10 11 12 13 17 18 19 20 21 22 28 30 33 34 35 36 37 38 39 40

Lowerlimit: 10
upperlimit: 30

These are the numbers between 10 and 30, you wrote:
 14 15 23 24 25 27 29 23 16 26
These are the numbers between 10 and 30, you didn't wrote:
 10 11 12 13 17 18 19 20 21 22 28 30

Lowerlimit: 0

Game over!


EDIT: For some reason the formatting got really screwed, but I hope you can read it anyway.
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 09-24-2007, 11:02 AM
Nousferatou Nousferatou is offline
Newbie
 
Join Date: Sep 2007
Posts: 7
Rep Power: 0
Nousferatou is on a distinguished road
Default

Alright thanks alot man!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

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


All times are GMT -5. The time now is 02:10 AM.

Contest Stats

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

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%


Complete - Celebrate!

Ads