pick a number

--Originally published at My life @ TEC

This program actually gave me a hard time, because I didn’t know how to declare a random number, so I read the book, I looked for answers online, I asked my dad and I also asked a friend, so when I finally understood how to do it, everything was easy from there until I tried to give the user chances to guess the number. I had to erase all the code to start again, it’s just that I wasn’t concentrated at all so it was hard, at the end I relaxed and it was easier that way.

Here’s my code:

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(){
int num1,num2,cont;
std::string resp;
do{
srand(time(NULL));
num1=1+rand()%(101);
cont=9;
cout<<“Hey! I’m thinking of a number between 0 and 100, guess wich one it is, you would have 10 chances to guess.”<<endl;
cin>>num2;
while (num2!=num1 & cont>0){
cont=cont-1;
if (num2>num1){
cout<<“sorry but “<<num2<<” is too high, try again.”<<endl;
cin>>num2;
}
else{
cout<<“sorry but “<<num2<<” is too low, try again.”<<endl;
cin>>num2;
}
}
if(num2!=num1){
cout<<“You couldn’t do it ? the number I was thinking was “<<num1<<endl;
}
else{
cout<<“¡Congratulations! “<<num2<<” is actually the number I was thinking”<<endl;
}
cout<<“Would you like to play again? (yes/no)”<<endl;
cin>>resp;
}while(resp!=”no”);
return 0;
}

and here’s how it works:

img_1483


Quiz #3

--Originally published at My life @ TEC

My first real quiz!! it was hard at the beggining and I was driving nuts! but I DID IT!!! ?

#include <iostream>
#include <math.H>
using namespace std;

double square_root(double x){
double param;
param=sqrt(x);
return param;
}
double cube_root(double x) {
double param;
param=cbrt(x);
return param;
}
int main () {
double x;
cout<<“hey, give a number!”<<endl;
cin>>x;
cout<<“the square root of “<<x<<” is: “<<square_root(x)<<endl;
cout<<“the cube root of “<<x<<” is: “<<cube_root(x);

return 0;
}


My first blog

--Originally published at My life @ TEC

hey everybody!! I´d like to introduce myself and give you a quick explanation of what my blog is about. All right, so first of all my name is Gustavo Hinojosa, and I to be honest with you I´m not really used to publish things o having a blog, I think that why it took me so long to opened jaja, but anyways I will give a try ? and about my blog, well i think you already what this is about, because I believe everyone has their own for the same thing, but anyways if don´t know why I made this blog, well I made to post all my works and homeworks that the teacher asks us to do.

I will be posting more of these so I hope you enjoy them, and I also hope they can be usefull at any time you need.

?