Need Help with Looping Structures for Class
I have this Visual Basic class I'm taking online. And the damn professor doesn't know how to communicate or assist his students at all. He even seems a little irritated when I ask for pointers.
I can't figure out these two assignments. Partly because I didn't get any sleep last night. Using the guidlines, can anyone help me out here? At this point in the section all I'm supposed to know about are Do, Do While, Do Until, Exit Do, Continue Do, and For Next loops. So try not to go off in a fancy super-coder direction. And everything is (preferably) made through Console Applications on VBE 2008
Problem 1:
Write a program that evaluates the factorials of the integers from 1 to 10 using an appropriate data type. (factorials are... factorial of 1 is 1, factorial of 5 is 120, or 1*2*3*4*5=120)
Problem 2:
Make a diamond - 1 asterisk at the top, 9 asterisks at it's widest - using only nested For...Next statements to print the asterisks AND spaces, minimizing use of output statements.
This stuff is retarded and difficult for me. Any pointers for a noob?
Re: Need Help with Looping Structures for Class
Problem 1 is solved using a for next loop
Code:
private function factorial(byval value as integer) as double
factorial=1
for count as integer = 1 to value step 1
factorial *= count
next
' factorial contains the value so end function
End Function
The problem given is a classic problem so you would be able to find plenty of solutions to this, it is a classic example which can be solved with a recursive function
problem 2 needs a lil more thought.
basically you are counting asterisks or spaces so line 1 will have 1 asterix and 4 spaces on either side, next line has 3 asterix with 3 spaces either side, next one has 5 asterix and 2 spaces either side, then 7 asterix one space and 9 asterix. then the routine goes back to 1 asterix. these problems are best realised by writing some kind of table.
Code:
[ ][*]
4 1
3 3
2 5
1 7
0 9
1 7
2 5
3 3
4 1
hope you can see the pattern in this and subsequently work out the nesting of loops needed.
p.s. with each loop either a space or an asterix will be displayed and obviously a line feed at the end of each line
Re: Need Help with Looping Structures for Class
I'll see if I can get something worthwhile working from your help.
It's a little confusing because the keywords you're using are very different from my VBE 2008.
But like I said, I'll try anyway. Thanks :)
Re: Need Help with Looping Structures for Class
Possibly might be in the wrong forum section too, I'm not sure. ^^;
Re: Need Help with Looping Structures for Class
I use VS 2008 and nothing special in my code, will definitely work with VBE2008