Need help urgently...

This is a discussion on Need help urgently... within the C Programming forums, part of the General Programming Boards category; I'm new to all this C programming. and I have this work I must do But I'm stuck at a ...

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    9

    Need help urgently...

    I'm new to all this C programming. and I have this work I must do But I'm stuck at a point and have no idea how to continue..

    that's the assignment : http://www.cs.bgu.ac.il/~prog111/wik...ssignment1.pdf I only made it till the 2 step and I could not figure out how to do it...

    that's my code so far:
    Code:
    #include <stdio.h>
    
    #define printStart printf("Please enter the width of your square, the max num of chars per line, and the max num of lines:\n")
    #define printTchau printf("Good Bye!\n")
    #define printMinus printf("-")
    #define printPlus printf("+")
    #define printSpecialFrame printf("@")
    #define printNormalFrame printf("#")
    #define printNewLine printf("\n")
    
    int main(){
    //write your code here
    	int width,length,numline;//width- size of a square,length- the max number of chars per line,numline-number of lines
    	int i,j,k,n;
    	do
    	{
    		printStart;
    		scanf("%d%d%d", &width,&length,&numline);
    	}
    	
    	while((width<=0)||(length<=0)||(numline<=0));
    	
    
    
    
    
    
    
    	
    		for (i=0; i<width ;i++)
    		{
    			for (j=0; j<width-i; j++)
    			{
    				printPlus;
    			}
    		       for (k=j; k<width; k++)
    			   {
    				   printMinus;
    			   }
    			printNewLine;
    			
    			
    			
    		} 
    	
    
    
    		
    
    
    	
    		printTchau;
    
    
    
    
    
    
    //end of code
    	return 0;
    }
    I'm only allowed to do it with these functions: IF, IF ELSE, CONTINUE, BREAK, FOR, WHILE, DO WHILE.

    Please Help!!

    Thank you!

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Welcome to the forum, NA84!


    I don't know how many forum members will have the time to devote to studying your assignment - just going through the funky functions like "printchau" is enough to make us reach for the Pepto.

    Nevertheless, what are you stuck on? Did you get that box's alternate their first line char, and that modulo number mod 2==0 can be used to figure that out easily?

    The more specific you can be, the better your help can be. Saying "I don't get it", is just saying the obvious, since you're here asking for help.

    Take an example of input - how would you solve this input, in plain English. No code Just step by step, write it out, one statement per line. You'll build your program from this "skeleton" of an algorithm.

    If you don't understand how to solve it like this, then you can't program the computer to do it, and you don't understand the problem yet, quite well enough.

    Note, but put off the details for now, and focus on the things the pdf shows. Be sure you understand the BROAD hints the teacher is giving you, in that pdf, to solve this.

    Drawing out one or two of these by hand, is a good way to see the patterns, and how they can be used in solving the problem.

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    9
    thanks for your attention.. I'll try to give it some more thought and to implement my ideasinto the code... if I'll fail I'll try to be more specific in my problem.

  4. #4
    Registered User
    Join Date
    Oct 2010
    Posts
    9

    any ideas?

    my code is printing squares that are build from + and -. I need to make it run itself all over untill it reaches the numbers of lines inserted by the user. after the first square I can't figure out how to make it double itself again... thats my code so far
    Code:
    #include <stdio.h>
    
    #define printStart printf("Please enter the width of your square, the max num of chars per line, and the max num of lines:\n")
    #define printTchau printf("Good Bye!\n")
    #define printMinus printf("-")
    #define printPlus printf("+")
    #define printSpecialFrame printf("@")
    #define printNormalFrame printf("#")
    #define printNewLine printf("\n")
    
    int main(){
    //write your code here
    	int width,length,numline;//width- size of a square,length- the max number of chars per line,numline-number of lines
    	int i,j,k,n=0,c=0,z;
    	do
    	{
    		printStart;
    		scanf("%d%d%d", &width,&length,&numline);
    	}
    	
    	while((width<=0)||(length<=0)||(numline<=0));
    	
    
    
    	
    	
    	
    	
    		
    		 for (i=0; i<width ;i++)
    	 
    			 
    		 {
    			 
    			while (c<length)
    			{
    			for (j=0; (j<width-i); j++)
    			{
                     printPlus;	
               c++;
    		   
    		   
    				if (c>=length)
    				break;
    					
    			}
    		 
    		    for  (k=j;k<width+i; k++)
    				  
    			{  
    			if (c>=length)
    				break;
    			
    			   printMinus;
    		    c++;
    			if (c>=length)
    				break;
    			} 
    		
    				
    			}
    			printNewLine;
    			c=0, n=0, k=0;
    		 }	
    
    		
    			
    	 	
    	
    
    
    	
    		printTchau;
    
    
    
    
    
    
    //end of code
    	return 0;
    }
    if any one has any ideas i'll be happy to hear. thx.
    btw I'm only allowed to use these functions: IF, IF ELSE, CONTINUE, BREAK, FOR, WHILE, DO WHILE.

  5. #5
    C-no_Ob Bennie98's Avatar
    Join Date
    Oct 2010
    Location
    Ledeberg, Ghent, East-Flanders, Belgium
    Posts
    49
    when i run this program my compiler gave me the error that your variable "Z" isn't being used.. so you can delete that one..

    furthermore... the output from the file isn't a square... it is just a rectangle...

    I can't help you because I myself am a noob at this ^^ maybe changing your compiler isn't a bad idea?
    Because Tetris Is Unrealistic.

    "The fear of death is the most unjustified of all fears, for there's no risk of accident for someone who's dead." - Albert Einstein

    "The Edge... there is no honest way to explain it because the only people who really know where it is are the ones who have gone over." - Hunter S. Thompson

    "I never think of the future. It comes soon enough." - Albert Einstein

  6. #6
    Registered User
    Join Date
    Oct 2010
    Posts
    9
    some variables are not being used cause It's still not ready so I don't really care about that at the moment... the inner loop is basicly making squares built from + and - .but the final shape depends on the user input. if you will enter the same width and length you'll get that square. thx anyway

  7. #7
    C-no_Ob Bennie98's Avatar
    Join Date
    Oct 2010
    Location
    Ledeberg, Ghent, East-Flanders, Belgium
    Posts
    49
    Quote Originally Posted by NA84 View Post
    some variables are not being used cause It's still not ready so I don't really care about that at the moment... the inner loop is basicly making squares built from + and - .but the final shape depends on the user input. if you will enter the same width and length you'll get that square. thx anyway
    ok i didn't test your program that much

    can't help U otherwise...
    Because Tetris Is Unrealistic.

    "The fear of death is the most unjustified of all fears, for there's no risk of accident for someone who's dead." - Albert Einstein

    "The Edge... there is no honest way to explain it because the only people who really know where it is are the ones who have gone over." - Hunter S. Thompson

    "I never think of the future. It comes soon enough." - Albert Einstein

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    If you make a char array[][], and fill it with the char's you need, instead of printing them right now, it's not too hard to walk through the exercise. Follow the assignment's solving suggestions, step by step.

    Using the array[][], you can see the contents of it in the debugger, and also see it change, as you step through your code. Big help, imo.

    Post your current code and the printout you now have, and I'll take a peek at it.

  9. #9
    Registered User
    Join Date
    Oct 2010
    Posts
    9
    I just made to the third step... I'm sure my code isn't very efficient but it works so far... take a look if you have any suggestions for the next step let me know. thx

    Code:
    #include <stdio.h>
    
    #define printStart printf("Please enter the width of your square, the max num of chars per line, and the max num of lines:\n")
    #define printTchau printf("Good Bye!\n")
    #define printMinus printf("-")
    #define printPlus printf("+")
    #define printSpecialFrame printf("@")
    #define printNormalFrame printf("#")
    #define printNewLine printf("\n")
    
    int main(){
    //write your code here
    	int width,length,numline;//width- size of a square,length- the max number of chars per line,numline-number of lines
    	int i,j,k,n=0,c=0,z;
    	do
    	{
    		printStart;
    		scanf("%d%d%d", &width,&length,&numline);
    	}
    	
    	while((width<=0)||(length<=0)||(numline<=0));
    	
    
    
    	
    	
    	
    	
    		
    		 for (i=0; i<width ;i++)
    	 
    			 
    		 {
    			 
    			while (c<length)
    			{
    			
    
    				for (j=0; (j<width-i); j++)
    			{
                     printPlus;	
            c++;
    		if (c>=length)
    			break;
    				 if (n>i)
    			{  printPlus;
    			c++;}
    		   
    		   
    				if (c>=length)
    				break;
    					
    			}
    		 n=0;
    		    for  (k=j;k<width+i; k++)
    				  
    			{  
    			if (c>=length)
    				break;
    			
    			   printMinus;
    		    n++;
    			   c++;
    			if (c>=length)
    				break;
    			} 
    		
    				
    			}
    			printNewLine;
    			c=0, k=0; n=0;
    		 }	
    
    		
    			
    	 	
    	
    
    
    	
    		printTchau;
    
    
    
    
    
    
    //end of code
    	return 0;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Urgently in need of help...!!!
    By patron in forum C Programming
    Replies: 8
    Last Post: 02-17-2008, 10:12 PM
  2. urgently required help!!!
    By ayesha noor in forum C Programming
    Replies: 9
    Last Post: 01-11-2007, 01:45 PM
  3. Need help urgently
    By jstevanus in forum C++ Programming
    Replies: 15
    Last Post: 12-09-2004, 11:30 AM
  4. Need Help Urgently
    By chener in forum C Programming
    Replies: 3
    Last Post: 06-26-2002, 05:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21