#WSQ6 factorial calculator

--Originally published at My lonely happy place

i was writing this blog a couple of days before, but i was in a rush and run out of time without finish it and don’t  really remember what i wanted to say about it, so i’ll reserve myself to put some pictures with maybe a simple explanation, some pics and the code Captura de pantalla (188)Captura de pantalla (189)

what i have done is jut make a function that calculates the factorial of a number and call it inside my main, this function need 1 income of data from the user to use it as a limit and know how far should it have to keep working, and then take two variables with value one and make a product betwen ponints, then one of those values take the value of the result and ads one to the another, and repeats the loop over and over and over again until the summed number reaches the limit number, and then return the multiplied number,  but it don’t take much time to realise that my program don’t work above fifteen, witch i think happens due to my program have to do a way to long process to keep running above that, and just returns a negative value.

as usual, some shots of how it works.

Captura de pantalla (191)

and also as usual here is write code because i know nobody is going to use it, but it’s a requirement of the task.

 

#include<iostream>
using namespace std;

int factorial(int factor)
{
int proceso=1;
int resultado=1;
while(proceso<=factor)
{
resultado=resultado*proceso;
proceso=proceso+1;
}
return resultado;
}

int main()
{
int primnum;
int secnum;
cout<<“please give me a number an i will give you the factorial of that number.”<<‘\n’;
cin>>primnum;
int primopera=factorial(primnum);
cout<<“the factorial of your number is:”<<primopera<<‘\n’;
char chose;
cout<<“if you want the factorial of another number please type y, if you dont please

Continue reading "#WSQ6 factorial calculator"

#WSQ04

--Originally published at My lonely happy place

i feel so happy because this is actually the first i solve myself without asking for help, even if it is a berry simple and basic program i feel like finally i’m making some kind of progress, there are some shots of my write programcaptura-de-pantalla-161Captura de pantalla (165).png   when i was working on the program i figure out that the easiest way to solve this kind of program was just to make couples of numbers , but when i run the program i got stuck, because if only work if i’ve got a pair amount of numbers but if i try with something like numbers from 1 to 9 or something like that my program will give me a wrong answer, so i put a bunch of useless couts in the middle of my bucle, hopping that that will help me figure out what was wrong, and i stay stuck during a couple of days with the answer right in front of my eyes, notice that i use two values to sum, one called comienzo and another called proceso, and when i run my program the way was write with a non pair amount of numbers at some point, most specifically just before the program ends  proceso and comienzo were the same number, so i just got to put an if that rest the middle number once it got summed twice to get te righ answer without modify in a significantly way mi program, as usual i here are a couple of screen shots of how it works

captura-de-pantalla-168Captura de pantalla (171).png as usual i will give mi code in text format, just because it its becoming a tradition to mention in my blogs, and in case you want to copy it i suggest to erase the bunch of crappy useless couts i put in the middle

#include<iostream>
using namespace std;

Continue reading "#WSQ04"

#WSQ03

--Originally published at My lonely happy place

i should start do programming at home, because i still a couple of weeks behind, any way here is another task that i have supposed to done during the last month, this time i have done the task about finding a random number that the computer is generating, as usual there are some screen shots of my code

captura-de-pantalla-154

captura-de-pantalla-155

this task resulted to be more complicated that i tough, at first i tried to keep it simple, just asking the user for a new number when his number wasn’t the right one, and it worked but when i run it i found myself stuck in the program trying to found the right answer, doing even more than two-hundred attempts (i’m not joking)    trying to found a number between one and one-hundred, so i decided to put a limit of ten in the number of attempts, but then no matter how many times i tried to run the program i was never able to successfully win the game, i always run out f attempts, an was then when i figure out that what i actually needed was to tell the player  if the number he need to find where a larger or smaller one, minimising the range of numbers in between he has to choose one, and making it a more user friendly game.

here is an screen shots of how it worked,Captura de pantalla (156).png

and here is what happens if you don’t find the answer.

Captura de pantalla (160).png

in case you want it (i hope you don’t because that will mean that you are as screwed up as i am) here is my code.

#include<iostream>
#include<time.h>
#include<stdlib.h>
using namespace std;

int main()
{
int numero;
int intento;
int numerodeintento;

srand(time(NULL));
numero=1+rand()%(101-1);

cout<<“tengo un numero entre 1 y 100, adivina cual es”<<‘\n’;
cin>>intento;
numerodeintento=10;

Continue reading "#WSQ03"

#WSQ03

--Originally published at My lonely happy place

i should start do programming at home, because i still a couple of weeks behind, any way here is another task that i have supposed to done during the last month, this time i have done the task about finding a random number that the computer is generating, as usual there are some screen shots of my code

captura-de-pantalla-154

captura-de-pantalla-155

this task resulted to be more complicated that i tough, at first i tried to keep it simple, just asking the user for a new number when his number wasn’t the right one, and it worked but when i run it i found myself stuck in the program trying to found the right answer, doing even more than two-hundred attempts (i’m not joking)    trying to found a number between one and one-hundred, so i decided to put a limit of ten in the number of attempts, but then no matter how many times i tried to run the program i was never able to successfully win the game, i always run out f attempts, an was then when i figure out that what i actually needed was to tell the player  if the number he need to find where a larger or smaller one, minimising the range of numbers in between he has to choose one, and making it a more user friendly game.

here is an screen shots of how it worked,Captura de pantalla (156).png

and here is what happens if you don’t find the answer.

Captura de pantalla (160).png

in case you want it (i hope you don’t because that will mean that you are as screwed up as i am) here is my code.

#include<iostream>
#include<time.h>
#include<stdlib.h>
using namespace std;

int main()
{
int numero;
int intento;
int numerodeintento;

srand(time(NULL));
numero=1+rand()%(101-1);

cout<<“tengo un numero entre 1 y 100, adivina cual es”<<‘\n’;
cin>>intento;
numerodeintento=10;

Continue reading "#WSQ03"