9 Replies - 1243 Views - Last Post: 08 October 2010 - 09:46 AM Rate Topic: -----

#1 rl1961  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 07-October 10

Help with figuring how to write a simple loop

Posted 07 October 2010 - 09:54 AM

I have an assignment to write a code that prints a "wheel" with a tire outer shell ("*"), a wheel inner portion ("$") and an axle (just a cross made out of "+")...I am not asking anyone to do my homework, but i can't get started...I can make a triangle, but I cannot seem to 'round it out to get a wheel with the desired form? Any help would be appreciated.

/* triangle.c program */

#include <stdio.h>
#include <stdlib.h>

int main()
{
  int row_width = 1;
  int rows = 0, x = 0, y = 0, a = 0; 
  int num_rows;
   

  printf("%s", "Please enter the number of rows\n");
  printf("Then press enter: ");
  
  scanf("%d", &rows);
	
  
  for(a = 0; a < rows; a++)
  {       
    for( y = num_rows; y > 0; y--)
	{
	  printf("%s", " ");
	}
	  num_rows --;

	for( x = 0; x < row_width; x++)
	{
	  printf("%s", "*");			
	}

	printf("\n");	
	row_width += 2;
				
	}
  system("PAUSE");
  return 0;
}


MOD EDIT: When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 07 October 2010 - 10:48 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Help with figuring how to write a simple loop

#2 eker676  Icon User is offline

  • C++ Programmer
  • member icon

Reputation: 318
  • View blog
  • Posts: 1,710
  • Joined: 18-April 09

Re: Help with figuring how to write a simple loop

Posted 07 October 2010 - 09:57 AM

I would start by printing out what you want to the console by hardcoding every line.

The console looks different then your text editor or IDE.

So hardcode it to see if it looks right and then write it with loops.

prinf("%5s", "*");
printf("%8s", "******");
/* etc.. */


Was This Post Helpful? 0
  • +
  • -

#3 rl1961  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 07-October 10

Re: Help with figuring how to write a simple loop

Posted 07 October 2010 - 10:49 AM

I am still lost???

I cannot figure out how to make a circle with the required fills?

View Posteker676, on 07 October 2010 - 08:57 AM, said:

I would start by printing out what you want to the console by hardcoding every line.

The console looks different then your text editor or IDE.

So hardcode it to see if it looks right and then write it with loops.

prinf("%5s", "*");
printf("%8s", "******");
/* etc.. */


Was This Post Helpful? 0
  • +
  • -

#4 newclearner  Icon User is offline

  • D.I.C Regular

Reputation: 103
  • View blog
  • Posts: 302
  • Joined: 29-September 10

Re: Help with figuring how to write a simple loop

Posted 07 October 2010 - 01:02 PM

View Posteker676, on 07 October 2010 - 09:27 PM, said:

I would start by printing out what you want to the console by hardcoding every line.

The console looks different then your text editor or IDE.

So hardcode it to see if it looks right and then write it with loops.

prinf("%5s", "*");
printf("%8s", "******");
/* etc.. */




A good exercise for me also. So far I have been able to print a small circle only( :oops: does it look like egg shaped).

Attached Image

As I increase the size it starts looking more like a trianle rather than a circle :P.

Will work on it tomorrow. Quite late here. Going to sleep. Night Night. :)

This post has been edited by newclearner: 07 October 2010 - 01:02 PM

Was This Post Helpful? 0
  • +
  • -

#5 rl1961  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 07-October 10

Re: Help with figuring how to write a simple loop

Posted 07 October 2010 - 01:59 PM

Thank you for the try ! But, I want to learn what to , I do not want someone giving it to me...I do really appreciate the help!
Was This Post Helpful? 0
  • +
  • -

#6 ishkabible  Icon User is offline

  • spelling expret
  • member icon





Reputation: 1530
  • View blog
  • Posts: 5,519
  • Joined: 03-August 09

Re: Help with figuring how to write a simple loop

Posted 07 October 2010 - 02:11 PM

why cant you do what eker676? it is for sure how i would do it as well. draw in some simply text editor if not with code then code it.

something like this maybe.

    *****
   **$$$**
  **$$$$$**
  *$$$+$$$*
  **$$$$$**
   **$$$**
    *****

This post has been edited by ishkabible: 07 October 2010 - 02:18 PM

Was This Post Helpful? 0
  • +
  • -

#7 eker676  Icon User is offline

  • C++ Programmer
  • member icon

Reputation: 318
  • View blog
  • Posts: 1,710
  • Joined: 18-April 09

Re: Help with figuring how to write a simple loop

Posted 07 October 2010 - 02:28 PM

You should approach this problem as a top-half and bottom-half problem.

First use loops to draw this:
  *****
 **$$$**
**$$$$$**



Draw the middle line:
*$$$+$$$*


Then use loops to draw this:
**$$$$$**
 **$$$**
  *****

Was This Post Helpful? 1
  • +
  • -

#8 rl1961  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 07-October 10

Re: Help with figuring how to write a simple loop

Posted 08 October 2010 - 06:08 AM

OK, Thank you I will try that!
Was This Post Helpful? 0
  • +
  • -

#9 rl1961  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 07-October 10

Re: Help with figuring how to write a simple loop

Posted 08 October 2010 - 07:54 AM

I don't understand what I am doing wrong ... I have been trying everything and it is getting worse, not better??

this is my output now...

Please enter the outter radius of the tire <40
then press enter: 20
Please enter the inner radius of the tire (must be less that outter radius)
then press enter: 10
*$$$$$$$$$$$
*$$$$$$$$$$$
*$$$$$$$$$$$
*$$$$$$$$$$$
*$$$$$$$$$$$
*$$$$$$$$$$$
*$$$$$$$$$$$
*$$$$$$$$$$$
*$$$$$$$$$$$
*$$$$$$$$$$$
*$$$$$$$$$$$
*$$$$$$$$$$$
*$$$$$$$$$$$
*$$$$$$$$$$$
*$$$$$$$$$$$
*$$$$$$$$$$$
*$$$$$$$$$$$
*$$$$$$$$$$$
*$$$$$$$$$$$
*$$$$$$$$$$$
*++++++++++
Press any key to continue . . .

any ideas?
Was This Post Helpful? 0
  • +
  • -

#10 ishkabible  Icon User is offline

  • spelling expret
  • member icon





Reputation: 1530
  • View blog
  • Posts: 5,519
  • Joined: 03-August 09

Re: Help with figuring how to write a simple loop

Posted 08 October 2010 - 09:46 AM

how about we look at your code. to steer you in the right direction look at what eker676 showed you. first look at the top part, what is the patter? first you have 5 asterisks, sounds like you should loop 5 times, no? then you have a pattern, 2 asterisks followed by (let i be the loop iterator)3+2i "$"'s and then two more asterisks. then you have the middle, one asterick, three money symbols(what do you call those?), one plus sign, then again (pattern) three money symbols, then again one asterick. the bottom is just the oppsite of the top so you simply goe back wards though it, 2 astericks, 5-2i money symbols, then two more astericks. then finlly 5 asterricks (sounds just like the top to me).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1