Quiz #2

For this quiz the program ask a base number and another number that you want to elevate the base number to the second number.

I search for help in cplusplus.com to look for a formula to make the exponent.

superpower1

Then I  apply it and at the end it work!!

Here is my code on Atom of both programs

superpower

And here the stars part

starquiz

And here is where it shows how the programs work

superpower3

The stars part star1

You can check my code here on Github.

 

 

 

Second Quiz

Another class, another quiz.

This time we were in charge of making loops. However, since I found out a the easy way, I used those methods.

For the first part we were in charge of ‘a’ be at ‘b’ power. In Python 3 this operatios is represented with “**”. So the code looks somehow like this:

quizpower.png

Then the second question requested us to print “*” a certain number of times in the same line. Even so it was forbidden, I used multipications to print x number of times the symbol “*”. Yet, I could not find out a way to print it at the same line. Still in the process of exploring other people’s blogs to see the other way to do this two exercises and to find out how to print in the same line.

Here code for part 2:

printstars.png

And this is how it runs!

printstars.png

Quizz 2

The image on top of this text has nothing to do with this quizz. Actually it has to do with the first quizz! I just tought that it looked cool. It is a screenshot of one of my assignments. Feel free to use it.

The time for quizz number two arrived today. What the proffesor intends to do with this quizzes is that his students get to know in what subjects they are not doing good, so they can get o study them!

This quizz was a little bit more challenging for me. I guess it´s normal, since I think difficulty should increase as time progresses. But anyway, this quizz was about Loops, basically. Here you can look at what we were asked to do:

quizz

In problem number one I had a little bit more difficulty solving it. I decided to use a For Loop inside a function called “superpower”, but I just couldn´t figure out what the operation had to be. I knew I had to multiply b times a*a. So what I basically did was that I created an int variable called “o” and I initialized it on 1. o = 1. Then, inside the for loop, I wrote o = 0 * a. Everything will make sense if you look at the code:

#include <iostream>

//Program1
//Ernesto Sánchez Bernal

using namespace std;

int x, y, o = 1;
int superpower (int a, int b){

for (int t = 1; t <= b; t++ ){

o = o * a;
}
return o;
}

int main(){

cout << “Provide the number you want to elevate to the power of another number: ” << endl;
cin >> x;

cout << “Provide the value of the power: ” << endl;
cin >> y;
cout << “The answer is: ” <<

Continue reading “Quizz 2”

Do – Quiz #2

Hey there, here is how I did my quiz, I use the learned from the On to the function, and I use to base myself on the code that our teacher show us for the function and then I write the code so it can work with the function. I did use do-while, and the program exit when the counter of loops reacher the same amount of the exponential number. Until the loop was running it multiply the ans of the past multiplication for x number that was imputed.

Here I leave you images of the console running and the atom editor:

Click to view slideshow.

Here I leave you the code in github:

https://gist.github.com/batmantec/3dbd1fde9e5bf46899cd

Quiz #2

#TC1017 #Quiz2

Problem 1: Superpower!

This pogramm asked the user for two numbers, so then the first number would be raised to the power of the second, which we all tought would be pretty easy to use with the pow function, but Ken actually wanted us to do some loops instead.

I approached this problem basically just as I did the WSQ08 one. I’m getting too comfortable using whiles and counters, I think it might be time to star using for statements to get out of the comfort zone. Ths programm was done quite quickly and efficiently I guess, I just had to multiply twice the counter in the sum equation to get the right number.

superpower.proof

Source code:

#include <iostream>
using namespace std;

int superpower (int first, int second)
{
int counter;
int sum;

do
{

counter++;
sum = first*counter*counter;
} while (counter != second);

cout << first << ” to the ” << second << ” power is: ” << sum << endl;

}
int main(){

int a, b;

cout << “Enter the first number:” << endl;
cin >> a;
cout << “Enter the second number:” << endl;
cin >> b;

superpower (a,b);

}

 

Problem 2: Display Stars

This problem actually was more of a challenge to me since I didn´t quite know how to approach it. But as I said before, I’m getting more and more comfortable using while statements, so after some hesitations that’s what I did, using counters yet again.

In order to display all the stars in just on row I took the ” << endl; ” bit out and it worked perfectly.

stars.proof

Source code:

#include <iostream>
using namespace std;

int starstoprint (int numberstars)
{
int counter;

while (numberstars != counter)
{
counter++;
cout << ‘*’;
}
}

int main(){

int number;
char decision;

Continue reading “Quiz #2”

Quiz#2

1.- Crear una función llamada superpower que eleve un numero x a y potencia

& yo usé dos input, luego un def en el que puse la operación ya definida de a,b (o x,y) al resultado le puse el nombre de z, finalmente imprimo el superpower

quiz2superpower

2.- Imprimir estrellas “*” cierto número de veces en una sola linea.

utilicé un for y para que se imprima en una sola linea es ,end=”” terminando el “*”… me gusta el número 42.

quiz2superpower