I have been trying to do my project for the past 2 weeks but cannot think of any other ways to make it works. This is an important project to me if I want to get a passing grade in this class. So if anyone think they can help me out with this, please feel free to do so because I can not think of a way to make it works. Thanks

project 1.
create the following diagram
use 2 while loop to control row and column
use if statement to determine if stars should be increased or decreased.

*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*

here is my here is what I came up with
(I am using Navajo)

#include <stdio.h>
int main (void)

{
int row;
int column;


row=1;

while (row<=9)
{

column=1;
while(column <=5)
{

printf("* ");
column++;
}
printf("\n");
row++;
}
if (row)
{
printf (" ");
row++;
}

else
{
printf(" ");
row--;
}
return 0;
}

and here is the diagram I got. It seem like my if/else statement is not recognize by the program. what is wrong with the code?

[nvan1@navajo ~]$ c++ project1.c
[nvan1@navajo ~]$ ./a.out
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
[nvan1@navajo ~]$

Recommended Answers

All 4 Replies

here your simply doing a loop that prints 5 character untill row becomes 9
and that code

if (row)
{
     printf (" ");
     row++;
}

else
{
     printf(" ");
     row--;
}

will never enter row-- since any non zero number is true what u should do is explain in insruction to yourself how to do this

so where should I start? can you please help..

well you could do this in puesdo code

#define test 5
for(n=0;n is less than or = to 9;increment n)
     if(n is less than test)
        for(int x=0;x is less then n;increment x) /*used for till max is found*/
             print(star)
    else its bigger than test //then we must do in reverse order 
          for(int x=n; x is less than or = to 9;increment x)
                  print(star);
     putnewline;
}

In case if you have not got the solution.. plese use this.

#define max 5
#include<stdio.h>
void main()
{
	int i,j;
	for(i=0;i<max;i++)
	{
		for(j=0;j<i;j++)
		{
			printf("%c",'*');
		}
		printf("\n");
	}
	for(i=max;i>0;i--)
	{
		for(j=i;j>0;j--)
		{
			printf("%c",'*');
		}
		printf("\n");
	}

}

Thanks,
Saphar

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.