# Help with figuring how to write a simple loop

Page 1 of 1

## 9 Replies - 1243 Views - Last Post: 08 October 2010 - 09:46 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=193932&amp;s=cedb2d2df9659c7df53759a0e953204b&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 rl1961

Reputation: 0
• 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!!!

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

• C++ Programmer

Reputation: 318
• 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.. */

```

### #3 rl1961

Reputation: 0
• 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?

eker676, 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.. */

```

### #4 newclearner

• D.I.C Regular

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

## Re: Help with figuring how to write a simple loop

Posted 07 October 2010 - 01:02 PM

eker676, 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( does it look like egg shaped).

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

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

### #5 rl1961

Reputation: 0
• 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!

### #6 ishkabible

• spelling expret

Reputation: 1530
• 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

### #7 eker676

• C++ Programmer

Reputation: 318
• 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:
```**\$\$\$\$\$**
**\$\$\$**
*****
```

### #8 rl1961

Reputation: 0
• 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!

### #9 rl1961

Reputation: 0
• 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...

then press enter: 20
then press enter: 10
*\$\$\$\$\$\$\$\$\$\$\$
*\$\$\$\$\$\$\$\$\$\$\$
*\$\$\$\$\$\$\$\$\$\$\$
*\$\$\$\$\$\$\$\$\$\$\$
*\$\$\$\$\$\$\$\$\$\$\$
*\$\$\$\$\$\$\$\$\$\$\$
*\$\$\$\$\$\$\$\$\$\$\$
*\$\$\$\$\$\$\$\$\$\$\$
*\$\$\$\$\$\$\$\$\$\$\$
*\$\$\$\$\$\$\$\$\$\$\$
*\$\$\$\$\$\$\$\$\$\$\$
*\$\$\$\$\$\$\$\$\$\$\$
*\$\$\$\$\$\$\$\$\$\$\$
*\$\$\$\$\$\$\$\$\$\$\$
*\$\$\$\$\$\$\$\$\$\$\$
*\$\$\$\$\$\$\$\$\$\$\$
*\$\$\$\$\$\$\$\$\$\$\$
*\$\$\$\$\$\$\$\$\$\$\$
*\$\$\$\$\$\$\$\$\$\$\$
*\$\$\$\$\$\$\$\$\$\$\$
*++++++++++
Press any key to continue . . .

any ideas?

### #10 ishkabible

• spelling expret

Reputation: 1530
• 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).