Thread: Help please.

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    12

    Exclamation Help please.

    My partner and I are running into a problem in a project we are doing. We are supposed to prompt for a nonnegative seed value, a range, and a number between (10 , 50) of random numbers to generate. The program does other various things after this. The program executes perfectly, but our tests are not working at all, it will pass through the program no matter what numbers you enter. If someone could please give me and example of the best way to test values it would be GREATLY appreciated.

  2. #2
    Registered User
    Join Date
    Feb 2010
    Posts
    36
    Instead of asking the program from others,you post your code.We will look on it and help you.We don't know what algorithm and how did you implement the code.For testing the values given by user,you can use if-else conditional statements or switch statements.
    The following simple example code.

    Code:
    #include	<stdio.h>
    	int
    main ( int argc, char *argv[] )
    {
    	int a;
    	printf ( "Enter the value:"  );
    	scanf("%d",&a);
    	switch(a)
    	{
    		case 0:
    			printf ( "Given Value is 0\n"  );
    			break;
    		case 1:
    			printf ( "Given Value is 1\n"  );
    			break;
    		default:
    			printf ( "Given Value is %d\n",a  );
    			break;
    	}
    	if(a>1)
    		printf ( "Given Value a is greater than 1\n"  );
    	else if(a==1)
    		printf ( "Given Value a is equal to 1\n"  );
    	else
    		printf ( "Given Value a is less than 1\n"  );
    	return 0;
    }
    Last edited by vivekraj; 03-04-2010 at 10:29 PM.

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    66

    Thumbs up

    Try this code , This is a simple code for comparing values ,

    Code:
    #define MIN_VALUE 10
    #define MAX_VALUE 50
    
            int
    main ( int argc, char *argv[] )
    {
            int a;
            printf ( "Enter the value:"  );
            scanf("%d",&a);
    
            ( a>=MIN_VALUE && a<=MAX_VALUE )?printf("Condition is passed :%d\nValue is in between %d and %d\n" ,a,MIN_VALUE , MAX_VALUE):printf("VAlue is not in between %d and %d\n" ,MIN_VALUE , MAX_VALUE);
    }
    If u paste your code then we can find what is the actual problem you are facing.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    You could simplify that printf statement. The only thing that changes between them is the not word. So make the condition around the not word depending on the a value.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed