Final project. Snake!!

--Originally published at My life @ TEC

hey guys!

I´ve been abscent for a while now, but here I am again ? so for our final project, my friend Fernando Pacheco a I did a game that I´m sure everybody knows it, the snake game from the old nokia’s cellphones.

at the beggining we started programming in atom as usual, but when we noticed it was not working we decided to try with an other editor, I tried with DEV-C++ and Fernando tried with Code::Blocks, mine did not work, but pacheco’s one did, so we used that one, I believe it was easier because it has its own compiler, so that made it easier to handle.

First we did all the functions and put the library,one of the libraries also didn’t work when we tried it out in atom, but with this one it did, once we finished everything we created a menu for the game and it was hard because it ran, but it did not do what we wanted so we spent a while in there trying to fugure out what was wrong , at the end, we decided to leave it without the last “while”

this is my code

#include<windows.h>
#include<iostream>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>

using namespace std;

int cuerpo[200][2];
int n = 1;
int tam = 5;
int x = 10, y=12;
int dir = 3;
int xc =30, yc=15;
int velocidad = 100, h=1;
int score = 0;

char tecla;

#define ARRIBA 72
#define IZQUIERDA 75
#define DERECHA 77
#define ABAJO 80
#define ESC 27

void gotoxy(int x, int y)
{
HANDLE hCon;
COORD dwPos;

dwPos.X = x;
dwPos.Y = y;
hCon = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hCon,dwPos);
}

void pintar(){
//lineas horizontales
for(int i = 2; i < 78 ; i++){
gotoxy(i,3); printf(“%c”,205);
gotoxy(i,23); printf(“%c”,205);
}

//lineas verticales
for(int i =

Continue reading "Final project. Snake!!"

Quiz 6 (week 8)

--Originally published at My life @ TEC

This program is realy easy I just declare two variables “x” & “y” both started at 0, then I printed x, after that x takes the value of x+y, then we just had to print y, and after that y takes the value of y+x, and you just repeat those steps whatever times you want.

Here’s my code:

quiz6

and here’s how it works:

cquiz6


So far, so good!

--Originally published at My life @ TEC

Professor Ken asked us to publish of how we were doing in his class, and how we felt about it. To be honest I think I´m doing more than ok in his class, I have done all the WSQ and I’m also learning new stuffs in his class, like  I mentioned before in my blogs. I still beleive I can do better, for example this last parcial, I didn’t post anything on twitter, so I should start doing that, beside that I think everything is going well, today he gave me my exam I got everything correct, I got a 91 as final grade, but just because, as I mentioned before, I didn’t post on twitter! :\

Something I really recommend you to do, is to go to Ken’s office to asked for help, or maybe not to his office, but to be in contact with him, and he will help you a lot with whatever you need, that will help you a lot.

 


Quiz #06

--Originally published at My life @ TEC

I was behind with this quiz, but you know better late than ever. In this quiz we did some exercises that ken asked us to realize.

The first one consisted in printing out the storage space for each type of variable, what i learned here, by going to ken’s office and asking him, was a new way to print things out, instead of using the “cout”, I used the “printf” and honestly I kind of liked more, anyways let me show you my code;

quiz51

and here’s how it works:cquiz51

the second one we had to convert some variables, for example a char with into an int, and that was pretty cool, also ken showed me a table called the “ascii table” where you can find what character corresponds to each number

asciifull

let me show you my code:

quiz52

I tried to did this one by using “printf” instead of “cout”and it actually worked, it gave some values, but they were not the ones I were looking for, then ken helped me and told me that printf and cout were not the same and that I had to choose wich one will work for what im trying to program. anyways here’s how it works:

cquiz52

the third one was really easy basicallyhe had to print this triangule

C i I s s b b e e s s t s e b s i C i s b e s t
and many of you might think it is really hard, but that’s not the case. let me show u my code:
quiz53

and here´s how it should look when you are running it:
cquiz53

with the fourth one I think it was the hardest but not impossible, you just had to ask the user for 3 numbers and print them in ascending order ,

cquiz54
quiz55
cquiz55
Continue reading "Quiz #06"

Lists :)

--Originally published at My life @ TEC

Hi! it’s me again, ok so in this program what we did is that we asked the user for 10 numbers and we give them the total, the average and the standard deviation. Honestly this was hard, I didnt know how to do it, but I learned the “for” loop, so that is good, I’m learning new ways to program.

here’s my code

#include
#include using namespace std;
int main (){
float lists[10], sum=0, average, stdev1=0, stdev, stdev3;
cout<<“hey! please give me 10 numbers”<<endl;
for (int i=0; i<10; i++){ cin>>lists[i];
sum=sum+lists[i];
}
average=sum/10;
for(int i=0; i<10; i++){
stdev+=pow(lists[i]-average,2);
}
stdev=sqrt(stdev/(10-1));
cout<<“the total is “<<sum<<“, the average is “<<average<<” and the standard deviation is “<<stdev<<endl;
return 0;
}

and here’s how it works:

lists


Factorial calculator :)

--Originally published at My life @ TEC

This program kind of tested me out, first of all, I didn´t know what a factorial number was, so I did some research, once I knew what it was, I started writing the code, and from there it was easy.

here’s the code:

#include <iostream>
using namespace std;
int main(){
int num;
std::string resp;
do{
int cont=0;
int sum=1;
cout<<“Hi! please give me a non-negative integer”<<endl;
cin>>num;
while(cont<num){
cont++;
sum=sum*cont;
}
cout<<“the value of “<<num<<” factorial is: “<<sum<<endl;
cout<<“Would you like to try another number? (y/n)”<<endl;
cin>>resp;
}while(resp!=”n”);
cout<<“Pleasure to meet you! have an excellent day!!”<<endl;
return 0;
}

and here’s how it works:

fcal


On to functions

--Originally published at My life @ TEC

So I´ve been absent for a while, but here I am again. I did this program like two weeks ago, but I didn´t post anything, anyways, this program was really easy, I used the original code of my first program, I just created the functions and applied them into the program.

Here´s the code:

#include <iostream>
using namespace std;
int sum(int x, int y){
int num=x+y;
return num;
}
int res(int x, int y){
int num=x-y;
return num;
}
int tim(int x, int y){
int num=x*y;
return num;
}
int div(int x, int y){
int num=x/y;
return num;
}
int main ()
{
int x,y;
cout<<“hi, enter the first number (X):”;
cin>>x;
cout<<“Enter the second number (Y):”;
cin>>y;

cout<<“X+Y=”<<sum(x,y)<<endl;
cout<<“X-Y=”<<res(x,y)<<endl;
cout<<“X*Y=”<<tim(x,y)<<endl;
cout<<“X/Y=”<<div(x,y )<<endl;
return 0;
}

and here’s how it works:

onto


sum of numbers!

--Originally published at My life @ TEC

What this program does, is that it asks you for two integers and it gives you the sum of all the numbers in that range, as simple as that, yeah sure…..

Hey I’m just kidding! it is not that hard but you have to keep in mind how you want your code to be, for example what I did, is that I put a loop whenever the user gave me a lower bound that was bigger than the upper bound, and it would be in that loop until he or she gave me a lower bound that was smaller than the upper bound.

Also I thought that maybe the user could enter the same two numbers as the lower bound and as the upper bound, and that was what it took me more time to do it, and I don´t know why, but anyways I was able to fix it.

Here’s my code:

#include <iostream>
#include <math.h>
using namespace std;
int main(){
int lowerb, upperb, sum=0, cont;
cout<<“Hey! please give me the lower bound”<<endl;
cin>>lowerb;
cout<<“Great! now please give me the upper bound”<<endl;
cin>>upperb;
while(lowerb>upperb){
cout<<“hey! you gave me a lower bound that is bigger than the upper bound, it is supposed to go the other way around. Try again”<<endl;
cout<<“Hey! please give me the lower bound”<<endl;
cin>>lowerb;
cout<<“Great! now please give me the upper bound”<<endl;
cin>>upperb;
}
cont=lowerb;
if(cont<upperb){
while(cont<=upperb){
sum=sum+cont;
cont=cont+1;
}
}
else{}
cout<<“The sum from “<<lowerb<<” to “<<upperb<<” (inclusive) is: “<<sum<<endl;
return 0;
}

and here’s how it works:

img_1484

 


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