Quiz 2

This quiz was about functions, they were many possible answers but it was expected that we use a loop or a recursion: 

The first one was: Create a program with the following function. Write a function called superpower that has receives two parameters (ints) and returns an integer which is first parameter raised to the power of the second, which is to say it returns a b . 

The second one: Create a program with the following function. Write a function called stars that has one parameter of type integer and PRINTS that many stars on a single line, so if we call the function with stars(5), the function will print like this: *****

Well I had to confess that this was a quiz that we had weeks ago, but at that time I didn´t know how to do it cz I didn´t know how to make a function and was not really sure how to do a Do-While. 

855

This was totally me when I saw the quizz LOL. Got it from: http://www.replygif.net/855

Now after investigating for making my WSQ’s and learning about how to make functions and Do-While, I was ready for this.

For making the first one I decided to use a Do-While. The first number would be multipling by itself until the «contador» (who was adding one each time the program repeated) was  the same value than the second number, who was the «raised to the ___ «.

While doing this program the first time I run it I noticed that I didn’t ask the user for the two values … JA-JA. (Not funny at all … ), the second time I run it… it did not work cz it was printing again the first value… and the third one (yes…you know what they say about the third one 🙂 ) it finally worked 😀 I just had to change the condition on the «while».  

Here is a link so you can see my code: Quiz 2 Ex. 1

El pase de diapositivas requiere JavaScript.

The second exercise was also about using a loop, so I decided to use a Do-While again. I used a ‘contador’ so the program would print an * until it reach the number that the user gives to the program. At first I was printing also the number so I took out the » cout << » that I had before calling the function and it worked correctly. 🙂

You can see my program here: Printing ‘ * ‘

quiz2parte2

Deja un comentario