#WSQ6 factorial calculator

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 type n.”<<‘\n’;
cin>>chose;
while(chose!=’y’ and chose!=’n’)
{
cout<<“please type y or n to continue.”<<‘\n’;
cin>>chose;
}
while(chose==’y’)
{
cout<<“please writhe a new number.”<<‘\n’;
cin>>secnum;
int segopera=factorial(secnum);
cout<<“the factorial of your second number is:”<<segopera<<‘\n’;
cout<<“if you want the factorial of another number please type y, if you dont please type n.”<<‘\n’;
cin>>chose;

}
while(chose==’n’)
{
cout<<“well then, have a nice day n.n”<<‘\n’;
break;
}
return 0;
}

thanks for reading, and if you leave a comment, a like or share my blogpost i’ll be very grateful.

#WSQ5 on to functions

finally i’m working on February tasks,  what a shame that the march month is also already running, i should spend more time trying to catch up before to get complitely screwed, instead of been watching videos and playing video-games the whole day, how ever, our main concern today is not my laziness, we are here today to talk about a task everyone of you have done like a month before i start to done it, i think every time i work in a new program it feels easier than the previous one, this program was basically about to repite the first program i have done, but instead of doing everything inside the main, once my professor showed me how to make, writhe and call them the program basically write itself captura-de-pantalla-181

today shots from the writen program will not be available because im writing it late in the night , i’m tired and want to sleep. so there is the code, and tanks for reading, bye bye n.n

#include
using namespace std;

int sum(int x, int y)
{
return x + y;
}
int diference(int x,int y)
{
return x – y;
}
int product(int x,int y)
{
return x * y;
}
int integer(int x,int y)
{
return x / y;
}
int reminder(int x,int y)
{
return x % y;
}
int main()
{
int a;
int b;
cout<<“please give me a number”<<‘\n’; cin>>a;
cout<<“please give me another number”<<‘\n’; cin>>b;
int suma = sum(a,b);
cout <<“the sum of your numbers is:”<< suma << ‘\n’;
int resta = diference(a,b);
cout <<“the diference betwen your numbers is:”<< resta <<‘\n’;
int multiplicacion = product(a,b);
cout <<“the product of your numbers is: “<< multiplicacion <<‘\n’;
int division = integer(a,b);
cout <<“the integerdivision betwen your numbers is: “<< division <<‘\n’;
int residuo = reminder(a,b);
cout <<“the reminder of your integer division is: “<< residuo << ‘\n’;
return 0;
}

#WSQ04

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
using namespace std;

int main()
{
int limiteinferior;
int limitesuperior;
int comienzo;
int proceso;
int limite;
int suma;
int total;

cout<<“we will calculate the sume of integers in the range you provide”<<‘\n’;
cout<<“please give us the lower bound:”<<‘\n’; cin>>limiteinferior;
comienzo=limiteinferior;
cout<<“please give us the upper bound:”<<‘\n’; cin>>limitesuperior;
limite=limitesuperior;
proceso=limite;
while(comienzo<=proceso)
{
suma=comienzo+proceso;
cout<<“comienzo”<<comienzo<<‘\n’;
cout<<“proceso”<<proceso<<‘\n’;
cout<<“limite”<<limite<<‘\n’;
cout<<“suma”<<suma<<‘\n’;
cout<<“total”<<total<<‘\n’;
comienzo=comienzo+1;
proceso=proceso-1;

total=total+suma;
if(comienzo==proceso)
{
total=total-proceso;
}
}
cout<<” the sum from “<< limiteinferior <<” to “<< limitesuperior << “(inclusive) is: “<<total<<‘\n’;
return 0;
}

as always, tanks for reading.

#WSQ03

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
#include
#include
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;
cout<<“numero de intentos”<<‘\n'<<numerodeintento<<‘\n’;
while (intento != numero)
{

if(intento<=numero)
{
cout<<“intenta con un numero mas alto”<<‘\n’; cin>>intento;
numerodeintento=numerodeintento-1;
cout<<“numero de intentos restantes”<<‘\n'<<numerodeintento<<‘\n’; } if(intento>=numero)
{
cout<<“intenta con un numero mas bajo”<<‘\n’; cin>>intento;
numerodeintento=numerodeintento-1;
cout<<“numero de intentos restantes”<<‘\n'<<numerodeintento<<‘\n’;

}
if(numerodeintento==0)
{
cout<<“lo siento, no te quedan intentos”<<‘\n’;
break;
}
}
if(intento==numero)
{
cout<<“felicidades, has encontrado el numero ganador”<<‘\n’;
}
if(intento!=numero)
{
cout<<“has fallado”<<‘\n’;
}
return 0;
}

and as always, thanks for reading.

#WSQ02

2i think that this task was actually easier that the previous one, the only source that i needed to achieve it was the task post, due to it is a really simple program, but i still needing to catch up with the class because i’m lazy as hell and still a couple of weeks behind.

here is my code:

#include
using namespace std;
int farenheit;
int celcius;

int main()
{
cout<<“Please give me the temperature in farenheit degrees”<<‘\n’; cin>>farenheit;
celcius=5*(farenheit-32)/9;
cout<<“the temperature in celcius degrees is”<<‘\n'<<celcius<<‘\n’;
if(celcius<=100)
{
cout<<“the water will not boil at that temperature (under typical conditions)”<<‘\n’; } if (celcius>=100)
{
cout<<“the water will boil at thar temperature (under typical conditions)”<<‘\n’;
}
return 0;

}

captura-de-pantalla-150

and here is an example of how it works

captura-de-pantalla-149

i really don’t have anything else to say about that so…

thanks for reading. n.n

WSQ 01 – Fun with Numbers

As always i’m the last student posting the assignments, but two weeks late i finally publish the first task i solve.

captura-de-pantalla-144

as always i try to solve the problem in the easiest way i can, ending up with a simple but funcional product.

captura-de-pantalla-145

and doing that way always worked to me n.n

if you want it, here is the code:

#include

#include
using namespace std;
int primernumero;
int segundonumero;
int main()
{
cout << “Please give me a number” << ‘\n’; cin >> primernumero;
cout << “Please give me another number” << ‘\n’; cin >> segundonumero;
cout << “the sume of your numbers is”<<‘\n'<<primernumero+segundonumero<<‘\n’;
cout<<“the diference betwen your numbers is”<<‘\n'<<primernumero-segundonumero<<‘\n’;
cout<<“the product of your numbers is”<<‘\n'<<primernumero*segundonumero<<‘\n’;
cout<<“the integerdivision of your numbers gives as a result”<<‘\n'<<primernumero/segundonumero<<‘\n’;
cout<<“the reminder of your division is”<<“\n”<<(primernumero%segundonumero)<<‘\n’;
return 0;
}

thanks for reading.

Quiz 3 Done… i guess :p

since i get stuck trying it by myself :p captura-de-pantalla-124

so i decide to browse the net to get an idea of what should i do :pcaptura-de-pantalla-142

and finally i gen an answer :v

here is my code, looks simple but works :p

#include
#include
using namespace std;
double square_root (double);
double cube_root (double);

double square_root (double x)
{
double y = 0;
y = sqrt(x);
return y;
}

double cube_root (double x)
{
double y = 0;
y = cbrt(x);
return y;
}

int main ()
{
double a;
cout << “\nplease input a number:” << endl; cin >> a;

cout << “\nThe square root of that number is ” << square_root(a) << endl;
cout << “\nThe cubic root of that number is ” << cube_root(a) << endl;
return 0;
}

Thanks for reading n.n

I need help

i’m trying to do the hello word thing that most of you must have done by now, but i don’t know how to compile my program using the Ubuntu bash thing, if someone can reply this post it will be very helpful.captura-de-pantalla-118

i really don’t have any idea of what else to do or where can i found  something related with my problem, i’ll be probably crying while i want for an answer, thanks for reading u.u .