Thread: If Statements wont stop?

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    36

    If Statements wont stop?

    ok im sure this is just something small im missing but im still missing it when i compile this and select an amount when the program is running it prints everything, however i only want it to print for the selected number. how can make this so it only prints the number i select? oh and the program is supposed to print the row headers of a k-map for the selected number of variables.

    Thank you
    Code:
    #include<stdio.h>
    int main(void)
    {
    int a;
    printf("Number of Variables (1-10): \n");
    scanf("%i", &a);
    
    if(a=1)
    	{
    		printf("\n0\n1\n");
    	}
    if(a=2)
    	{
    		printf("\n0\n1\n");
    	}
    if(a=3)
    	{
    		printf("\n00\n01\n11\n10\n");
    	}	   
    if(a=4)
    	{
    		printf("\n00\n01\n11\n10\n");
    	}	   	   
    if(a=5)
    	{
    		printf("\n000\n001\n011\n010\n100\n101\n111\n110\n");
    	}	   	   
    if(a=6)
    	{
    		printf("\n000\n001\n011\n010\n100\n101\n111\n110\n");
    	}	   
    if(a=7)
    	{
    		printf("\n000\n001\n011\n010\n100\n101\n111\n110\n");
    	}	  	   
    if(a=8)
    	{
    		printf("\n0000\n0001\n0011\n0010\n0110\n0111\n0101\n0100\n1100\n1000\n1001\n1011\n1010\n1110\n1111\n1101\n");
    	}	 
    if(a=9)
    	{
    		printf("\n0000\n0001\n0011\n0010\n0110\n0111\n0101\n0100\n1100\n1000\n1001\n1011\n1010\n1110\n1111\n1101\n");
    	}
    if(a=10)
    	{
    		printf("\n00000\n00001\n00011\n00010\n00110\n00111\n00101\n00100\n01100\n01000\n01001\n01011\n01010\n01110\n01111\n01101\n10000\n10001\n10011\n10010\n10110\n10111\n10101\n10100\n11100\n11000\n11001\n11011\n11010\n11110\n11111\n11101\n");
    	}	 	   	   	      	       
    return a;
    }
    thanks guys
    Last edited by litzkrieg; 02-23-2011 at 01:43 PM.

  2. #2
    Registered User
    Join Date
    Jan 2011
    Posts
    36
    Sorry if its alittle wide i should have checked that, my bad sorry

  3. #3
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    '=' is assignment, '==' is equality.
    Use 'else if' after your first 'if', it's better and faster. ( After all, 'a' can only have one value )
    Devoted my life to programming...

  4. #4
    Registered User
    Join Date
    Jan 2011
    Posts
    36
    Perfect thank you just starting to learn this fun little lang.

  5. #5
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Quote Originally Posted by litzkrieg View Post
    Perfect thank you just starting to learn this fun little lang.
    Hey, don't mention it!
    Keep it up, you're doing great. As a beginner, your primary goal must be to try to understand what the heck your compiler is talking about when there's an error!
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fscanf %s or %d integer input space char stop question...
    By transgalactic2 in forum C Programming
    Replies: 5
    Last Post: 04-14-2009, 10:44 AM
  2. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  3. Error stop Http Listener
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 06-04-2008, 02:14 AM
  4. Efficiency of case statements
    By Yasir_Malik in forum C Programming
    Replies: 26
    Last Post: 05-23-2006, 11:36 AM
  5. when a while loop will stop ?
    By blue_gene in forum C Programming
    Replies: 13
    Last Post: 04-20-2004, 03:45 PM

Tags for this Thread