Question Please ????

This is a discussion on Question Please ???? within the C Programming forums, part of the General Programming Boards category; Hi there.... I have a problem with one of my programs ...and here is the question " The program is ...

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    7

    Question Please ????

    Hi there....

    I have a problem with one of my programs ...and here is the question
    " The program is to input five numbers between 1 and 30 such that it gives the output of each number as the corresponding number of asterisks"



    the problem is that when I run the program it make me enter the number 2 times then to show the corresponding asterisks......so please any one answer me



    Thank You

  2. #2
    Epy
    Epy is offline
    Fortran lover Epy's Avatar
    Join Date
    Sep 2009
    Location
    California, USA
    Posts
    949
    Post the code

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    7
    download it .....


    The Code.txt

  4. #4
    Registered User
    Join Date
    Apr 2010
    Posts
    7
    hey......did you find it ?????

  5. #5
    Registered User
    Join Date
    Apr 2010
    Posts
    7
    Code:
    #include <stdio.h>
    
    int main()
    {
    	int counter =1;
    	int x;
    	
    		
    		printf( " Enter numbers between 1 to 30 \n " );
    		
    	while( counter <= 5 ){
    			
    		
    	
    		printf( "\nEnter the number\n " );
    		scanf( " %d " ,&x );
    
    					while( x <= 30 ){
    		
    
    								x = x - 1;
    								printf( "*" );	
    
    
    									if( x == 0 )
    									{
    										break;
    										}
    			
    												}
    		
    		counter = counter + 1;
    		
    	}
    
    	printf( " \nThe End\n\n " );
    
    
    		return 0;
    
    
    }

  6. #6
    Registered User
    Join Date
    Apr 2010
    Posts
    51
    first, can you write a code to print the amount of * equal to a number the user inputs?

  7. #7
    Registered User
    Join Date
    Nov 2009
    Location
    Italy
    Posts
    65
    Code:
    scanf( " %d " ,&x );
    Check it..

  8. #8
    Registered User
    Join Date
    Apr 2010
    Posts
    7
    I already did it in the code shown......

    in the loop >>>>>> while( x <= 30 )....it will do successive subtraction from the number the put * to each 1 subtracted until the number is zero it came out of this loop and increase the counter and so on.....

  9. #9
    Registered User
    Join Date
    Apr 2010
    Posts
    7
    @ rob90

    what do you mean by checking it .....

    I know that something must be done before something but I don't get it !!!!!

  10. #10
    Registered User
    Join Date
    Nov 2009
    Location
    Italy
    Posts
    65
    Since you still dont get it I'll tell you, you put an extra space in the scanf() function, change it with
    Code:
    scanf("%d", &x);
    Moreover you can simplify you program by doing something like:
    Code:
    scanf("%d", &x);
    for(j=0;j<x;j++) putchar('*');
    .... // continue the loop
    You dont need to make any subtraction
    Last edited by rob90; 04-20-2010 at 07:28 AM.

  11. #11
    Registered User
    Join Date
    Apr 2010
    Posts
    7
    IT REALLY WORKS


    really thank you for your help...."Grazie mille"...

    Thanks

  12. #12
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    This is the problem:
    Code:
    scanf( " %d " ,&x );
    Take the spaces out of the quotes.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

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