Thread: Please help me with my C programming

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2011
    Location
    Stockholm, Sweden
    Posts
    131
    Quote Originally Posted by Bx2 View Post
    thanks, that is better. now how can I get the error to loop back to ask the user the same question again? I know I need while, but am unsure how to implement it
    You can use a while loop, where the condition is the user input. i.e., loop while user input is not equal to 'q' or whatever the user is supposed to enter to quite the calculations.

  2. #2
    Registered User
    Join Date
    Oct 2011
    Posts
    8
    okay, so I've been messing around with the code, and I still cant get the hang of the do while loop. can anybody explain to me exactly what I'm doing wrong? also the total always equals $0. here is my current code:
    Code:
    main() { /*Written by Brandon Benyacar*/
    
    	int area, labour, length, width, height=8, ceiling, setup=100, paint;
    	float total, room;
    
    {printf("Painting Cost Estimator \n Enter length of room in feet: \n"); /*prompt user to input values*/
    scanf("%d", &length);
    	printf("Enter width of room in feet: \n ");
    	scanf("%d", &width);}
    	
    {{		printf("Please select grade of paint to use for walls: \n 1 - Basic \n 2 - Regular \n 3 - Premium \n"); /*assign cost to paint*/
    		scanf ( "%d", &paint );
    		
    			if( paint == 1 ) 
    				paint = 20;	
    		else
    			if( paint == 2 )
    				paint = 30;
    		else
    			if( paint == 3 )
    				paint = 40;
    			
    		else 
    		printf ("Please select a grade of paint that actually exists!!! \n");}
    			while ( paint <= 0 || paint > 3 );	}
    				
    				
    		
    	   
     
    { printf("Enter if ceiling is to be painted: \n 1 Yes \n 2 No \n");  /* Define whether ceiling is to be included in cost*/
    	scanf("%d", &ceiling);
    	while ( ceiling = 0 || ceiling > 2 );
    		if( ceiling == 1 )
    			ceiling = (length*width);
    	else
    		if( ceiling == 2 ) 
    			ceiling = 0;
    	else
    		printf ("You made an incorrect selection. Please choose whether the ceiling is to be painted: \n");}
    		
    {area=(2*length*height)+(2*width*height)+ceiling;
    printf("%d sq.feet \n", area);}
    
    {labour=(area/200)*2;
    room=((area)*paint)*2;
    total=room+setup+labour;
    printf ("Total: $%d \n", total);
    }
    }
    keep in mind ive been messing around with the code so not every little detail will be exactly as intended.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. About Device Driver Programming And Socket Programming
    By pritesh in forum Linux Programming
    Replies: 6
    Last Post: 01-23-2010, 03:46 AM
  2. Replies: 1
    Last Post: 08-19-2007, 03:55 AM
  3. small programming job VCPP / Object Oriented Programming
    By calgonite in forum Projects and Job Recruitment
    Replies: 10
    Last Post: 01-04-2006, 11:48 PM
  4. Total newb to programming here... Question about the many programming languages. Ty!
    By tsubotakid1 in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 10-05-2003, 10:32 AM

Tags for this Thread