www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - soooo who wants to help me figure out my D shortcomings

reply "Tori " <rshenely yahoo.com> writes:
/* licenced under the wtfpl license :D... as if i even understand 
how to license*/




import std.stdio;

void main(){
	//yeah... im making a diamond pattern out off asterisks
	writeln("Pick a number that is odd");
	int chosen;
	bool oddnoteven = false;
	while(oddnoteven == false){
		write("Enter number here: ");
		readf(" %s", &chosen);
		int numbercheck = chosen % 2;
		if(numbercheck == 0){
			writeln("I really don't like even numbers mofo >:/... Just odd 
ones.. Try again? :D");
		}
		else{
			oddnoteven = true;
		}
	}
	
	int peak = (chosen + 1)/2;
	
	
	for(int counter = 0; counter < chosen + 1; ++counter){ // this 
is my fro block.
		//Ok its not broken DO NOT KILL THE BLOCK!!!!!
		if(counter < peak){
			int spacesneeded = (peak - counter) - 1;
			for(int spacesmade = 0 ; spacesmade < spacesneeded; 
++spacesmade ){
				write(" ");
			}
			int shotsneeded = (2*counter) + 1;//(countxXXXerx + 1) +x 
(counterx + 1)/xxxxx2; uhh nope
			for(int shotsmade = 0; shotsmade < shotsneeded; ++shotsmade){
				write("*");
			}
			writeln();
		}
		//hmmm bastard block... >:/
		if(counter > peak){
			int spacesneeded = (counter - peak);
			for(int spacesmade = 0; spacesmade < spacesneeded; 
++spacesmade){
				write(" ");
			}
			int shotsneeded = (2*(chosen - counter))+ 1;
			for(int shotsfired = 0; shotsfired < shotsneeded; 
++shotsfired){
				write("*");
			}
			writeln();
		}
	}
}

so this prog is supposed to take an odd num and ouput some 
diamond shape in le terminal. sooo i know it may not be the best 
specim in ze world but i gotta know why the gnarly fakk i had to 
add "+1" to "chosen" for the standard stacker, it just cuts off 
the last print of my asterik on my bastard block if i dont have 
the "+1" setup. enlighten me please :D
May 30 2013
parent reply "Nicolas Guillemot" <nlguillemot gmail.com> writes:
You should post this to D.learn.
My advice is to rewrite this program while thinking more about 
math. It could be made much much simpler.
May 30 2013
parent "Tori " <rshenely yahoo.com> writes:
On Friday, 31 May 2013 at 05:02:30 UTC, Nicolas Guillemot wrote:
 You should post this to D.learn.
 My advice is to rewrite this program while thinking more about 
 math. It could be made much much simpler.

Ok ty for the advice :)
May 30 2013