Thread: True / False

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    124

    True / False

    I am trying to make this program run until 5 numbers between 50 and 100 are entered.
    What am I doing wrong?

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    #define TRUE 1
    #define FALSE 0
    
    #define SIZE 5
    
    //prototype
    int isValid(input);
    
    
    main(){
    
    	int values [SIZE]={0};
    	int count;
    	int i;
    	int valid;
    	int result;
    	int validSoFar;
    	count=0;
    	result=0;
    	i=0;
    	validSoFar=0;
    
    
    	for (i=0; i<SIZE; i++){
    		printf("Enter an integer (50-100):\n");
    		scanf("%i",&values[i]);
    		valid =isValid(values[i]);
    
    if (result=FALSE){
    			i--;}
    		validSoFar+=valid;
    
    		
    		//unique=isUnique(values);
    		printf("so far valid %i\n",validSoFar);
    	}
    
    	system("pause");
    }
    
    int isValid(int input){
    	int result,i;
    	if (input>=50 && input <=100)
    		result= TRUE;
    
    	else 
    		result= FALSE;
    	return result;
    }

  2. #2
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Your problem is in this part of the code:

    Code:
    if (result=FALSE){
    			i--;}
    		validSoFar+=valid;
    See if you can figure it out.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by goran00 View Post
    What am I doing wrong?
    if (result=FALSE)

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by tabstop View Post
    if (result=FALSE)
    That's not the whole problem though.

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    if (result=FALSE)

    That's better.

  6. #6
    Registered User
    Join Date
    Jan 2008
    Posts
    124
    i have tried using valid instead of result and 0instead of false, but its still not working.

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by goran00 View Post
    i have tried using valid instead of result and 0instead of false, but its still not working.
    You've got to fix the red part, too. (Using valid has the added benefit of having a chance of working, as opposed to result.)

  8. #8
    Registered User
    Join Date
    Jan 2008
    Posts
    124
    you mean i have to fix the equal sign?

  9. #9
    Registered User
    Join Date
    Jan 2008
    Posts
    124
    i think i got it. i used ==

  10. #10
    Registered User
    Join Date
    Jan 2008
    Posts
    124
    == worked. thank you.
    what I am trying to do now is figure out if the number entered is unique (if it hasn't been entered already).
    here is what I have so far.
    any hints on how to proceed.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    #define TRUE 1
    #define FALSE 0
    
    #define SIZE 5
    
    //prototype
    int isValid(input);
    
    
    main(){
    
    	int values [SIZE]={0};
    	int count;
    	int i;
    	int valid;
    	int result;
    	int validSoFar;
    	int unique;
    	count=0;
    	result=0;
    	i=0;
    	validSoFar=0;
    
    
    	for (i=0; i<SIZE; i++){
    		printf("Enter an integer (50-100):\n");
    		scanf("&#37;i",&values[i]);
    		valid =isValid(values[i]);
    		unique=isUnique(values);
    	
    		if (valid ==FALSE){
    			i--;}
    		
    		validSoFar+=valid;
    
    
    	
    		printf("so far valid %i\n",validSoFar);
    	}
    
    	system("pause");
    }
    
    int isValid(int input){
    	int result
    	int i;
    	if (input>=50 && input <=100)
    		result= TRUE;
    
    	else 
    		result= FALSE;
    	return result;
    }
    
    int isUnique (int inputData[], int elements){
    	int result;
    	int i;
    	for (i=0; i<5; i++){
    		if (input
    			result=TRUE;
    		else
    			result=FALSE;
    		return result;
    	}

  11. #11
    Registered User
    Join Date
    Jan 2008
    Posts
    124
    i have made a couple of changes and this is what I have.
    where do I go from here
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    #define TRUE 1
    #define FALSE 0
    
    #define SIZE 5
    
    //prototype
    int isValid(input);
    
    
    main(){
    
    	int values [SIZE]={0};
    	int count;
    	int i;
    	int valid;
    	int result;
    	int validSoFar;
    	int unique;
    	int uniqueSoFar;
    	count=0;
    	result=0;
    	i=0;
    	validSoFar=0;
    	uniqueSoFar=0;
    
    	for (i=0; i<SIZE; i++){
    		printf("Enter an integer (50-100):\n");
    		scanf("&#37;i",&values[i]);
    		valid =isValid(values[i]);
    		unique=isUnique(values);
    	
    		if (valid ==FALSE){
    			i--;}
    		
    		validSoFar+=valid;
    		uniqueSoFar+=unique;
    
    	
    		printf("so far valid %i\n",validSoFar);
    		printf("Unique so far %i\n",uniqueSoFar);
    	}
    
    	system("pause");
    }
    
    int isValid(int input){
    	int result;
    	int i;
    	if (input>=50 && input <=100)
    		result= TRUE;
    
    	else 
    		result= FALSE;
    	return result;
    }
    
    int isUnique (int values[], int elements){
    	int result;
    	int i;
    	for (i=0; i<5; i++){
    		if (values[i] =elements)
    			result=FALSE;
    		else
    			result=TRUE;
    	}
    	return result;
    }

  12. #12
    uint64_t...think positive xuftugulus's Avatar
    Join Date
    Feb 2008
    Location
    Pacem
    Posts
    355
    Code:
    		unique=isUnique(values);
    You haven't prototyped the function isUnique.
    You are calling it with the wrong number of arguments.
    Code:
    ...
        goto johny_walker_red_label;
    johny_walker_blue_label: exit(-149$);
    johny_walker_red_label : exit( -22$);
    A typical example of ...cheap programming practices.

  13. #13
    Registered User
    Join Date
    Jan 2008
    Posts
    124
    here is the new code, but it still doesnt work
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    #define TRUE 1
    #define FALSE 0
    
    #define SIZE 5
    
    //prototype
    int isValid(input);
    int isUnique(input);
    
    main(){
    
    	int values [SIZE]={0};
    	int count;
    	int i;
    	int valid;
    	int result;
    	int validSoFar;
    	int unique;
    	int uniqueSoFar;
    	count=0;
    	result=0;
    	i=0;
    	validSoFar=0;
    	uniqueSoFar=0;
    
    	for (i=0; i<SIZE; i++){
    		printf("Enter an integer (50-100):\n");
    		scanf("&#37;i",&values[i]);
    		valid =isValid(values[i]);
    		unique=isUnique(values[i]);
    	
    		if (valid ==FALSE){
    			i--;}
    		
    		validSoFar+=valid;
    		uniqueSoFar+=unique;
    
    	
    		printf("so far valid %i\n",validSoFar);
    		printf("Unique so far %i\n",uniqueSoFar);
    	}
    
    	system("pause");
    }
    
    int isValid(int input){
    	int result;
    	int i;
    	if (input>=50 && input <=100)
    		result= TRUE;
    
    	else 
    		result= FALSE;
    	return result;
    }
    
    int isUnique (int values[], int elements){
    	int result;
    	int i;
    	for (i=0; i<5; i++){
    		if (elements==values)
    			result=FALSE;
    		else
    			result=TRUE;
    	}
    	return result;
    }

  14. #14
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Continued here?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help making a dot bounce up and down y axis in this prog
    By redwing26 in forum Game Programming
    Replies: 10
    Last Post: 08-05-2006, 12:48 PM
  2. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 02:39 PM
  3. 1 or 0 == true or false?
    By Discolemonade in forum C++ Programming
    Replies: 4
    Last Post: 08-14-2005, 04:08 PM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  5. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 07:48 PM