Anduril, take a look at this.
Code:
/*This program should print diamond shapes composed of * characters*/
#include <stdio.h>
#include <math.h>
void flush(void)
{
while (getchar() != '\n')
;
}
int main(void)
{
/*Initialize variables*/
int row, num=0, space, stars, i, star, spaces, count=0;
char yes, more ='a';
do{
do{
printf("enter ODD size > 0: ");
scanf("%i", &num);
count = scanf("%i", &num);
if (count == 0){
printf("must enter integer\n");
flush();
}
}while (count != 1);
do{
if ((int)num%2 != 1){
printf("%i is not odd and > 1\nenter ODD size > 0: ",num);
scanf("%i", &num);
}
}while ((int)num%2 !=1);
for (row = 1; row <= num; row+=2 )
{
i = (num/2 - row/2);
for (space = i; space >= 1; space--)
{
printf(" ");
}
for (stars = 1;stars <= row; stars++)
{
printf("*");
}
printf("\n");
}
for (row = (num - 2); row >= 1; row -= 2)
{
i = (num/2 -row/2);
for (spaces = i; spaces >= 1; spaces--)
{
printf(" ");
}
for (star = row; star >= 1; star--)
{
printf("*");
}
printf("\n");
}
flush();
printf("more? ");
scanf("%c",&more);
}while (more == "y" || "Y");
return 0;
}
There are a few bugs. At first it asks for input, but it wont print anything unless I enter something (int/float/char) and then enter the number I want it to print. Also, for floating point values, I want to just truncate the value so it prints 7 instead of 7.25, etc. Any ideas?