# Use of diferent Functions

--Originally published at how not to program

Here is a code showing diferent functions

#include <iostream>
using namespace std;

int num1, num2, res, dif, mul;
float div;
int resta(int a, int b)
{
dif = a – b;
return (dif);
}
int mult(int a, int b)
{
mul = a * b;
return (mul);
}
int residuo(int a, int b)
{
res = a % b;
return (res);
}
float division(int a, int b)
{
div = a / b;
return (div);
}

int main(){
cout << “Introduce dos numeros. ” << endl;
cin >> num1 >> num2;
cout << “La resta es: ” << resta(num1,num2) << endl;
cout << “La multiplicacion es: ” << mult(num1,num2) << endl;
cout << “El residuo es: ” << residuo(num1,num2) << endl;
cout << “La division es: ” << division(num1,num2) << endl;
return 0;
}

# Guess the code

--Originally published at how not to program

Here is an other guess the code, guess what the code do in the comments

#include <iostream>
#include <string>
using std::string;
using std::cout;
using std::cin;
using std::endl;

int main(){
string palabra, alreves, respuesta;
cout << “Dame la palabra ” << endl;
cin >> palabra;

// cout << palabra;

int tamano = palabra.length();
for(int i = tamano-1; i>=0; i–){
// cout << palabra[i];
alreves = alreves + palabra[i];
}
cout << alreves << endl;
if(palabra == alreves)
{
cout << “Es palindromo ” << endl;
}
else
{
cout << “No es palindromo ” << endl;
}
}

# Guess the code

--Originally published at how not to program

Here is a new code, guess what it does

#include <iostream>

using namespace std;

int a , b, c, d;

int main()
{
cout << “escribe un numero” << endl;
cin >> a;
cout << “escribe otro numero” << endl;
cin >> b;
cout << “escribe otro numero” << endl;
cin >> c;
cout << “escribe otro numero” << endl;
cin >> d;
if (a>b){

if (a>c)
{
if (a>d){

cout << “El primer numero es mas grande que todos ” << endl;
}
}
}
else {

cout << ” mejor me mato ” << endl;
}
return 0;
}

--Originally published at how not to program

Here is a code of how to use comments

#include <iostream>

using namespace std;
// Add a Double “//” then just type. The program will ignore the text after the “//”
int main()
{
cout << “Hello world!” << endl;
// No matter where in the code it is

/* you can also use “/*” to start a coment but you need to close it just like a parenthesis with “* /” */

return 0;

}

# Final project

--Originally published at how not to program

Here is the final result of our final project. its about a code that gets the coordenates for a solid for you to graph it. I worked with Josue reyes and Rodrigo Zermeño

#include <iostream>
#include <fstream>
#include <cmath>
#define pi 3.14159

using namespace std;

char figura;
int HP, LP1, LP2, HC, RC;
float x, y, z;

int main(){
cout << “Que figura quieres (C=Cilindro/P=Prisma): “;
cin >> figura;
if((figura== ‘c’) || (figura== ‘C’)){
cout << “Ingresa la altura en milimetros (No mayor a 1000 mm): ” << endl;
cin >> HC;
cout << “Ingresa el radio en milimetros (No mayor a 1000 mm): ” << endl;
cin >> RC;
ofstream myfile;
myfile.open(“ArchivoCilindroProyecto.txt”);
myfile << “Las coordenadas del cilindro son: ” << endl;
for(z=0; z<=HC; z++){
for (int x=RC; x>=-RC; x–){
y=sqrt(pow(RC,2)-pow(x,2));
myfile << “(” << x << “,” << y << “,” << z << “)” << endl;
}
for (int x=RC-1; x>=-RC+1; x–){
y=sqrt(pow(RC,2)-pow(x,2));
myfile << “(” << x << “,-” << y << “,” << z << “)” << endl;
}
for (int y=RC; y>=-RC; y–){
x=sqrt(pow(RC,2)-pow(y,2));
myfile << “(” << x << “,” << y << “,” << z << “)” << endl;
}
for (int y=RC-1; y>=-RC+1; y–){
x=sqrt(pow(RC,2)-pow(y,2));
myfile << “(-” << x << “,” << y << “,” << z << “)” << endl;
}
}
}else if((figura== ‘p’) || (figura== ‘P’)) {
cout << “Ingresa la altura en milimetros (No mayor a 1000 mm): “;
cin >> HP;
cout << “Ingresa el lado 1 de la base en milimetros (No mayor a 1000 mm): “;
cin >> LP1;
cout << “Ingresa el lado 2 de la base en milimetros (No mayor a 1000 mm): “;
cin >> LP2;
ofstream myfile;
myfile.open(“ArchivoPrismaRectangularProyecto.txt”);
myfile << “Las coordenadas del Prisma

# for and nested for

--Originally published at how not to program

Here is a code showing how to do a nested for

#include <iostream>

using namespace std;
int a;

int main()
{
cout << “For example ” << endl;
for (int x= 0 ; x <= 10;x++ ) {
cout << “Este es el ciclo numero ” << x << endl;

}
cout << “——————————————————————————–” << endl;
cout << “Nested For example ” << endl;

cout << ” ” << endl;
for (int z = 0 ; z >= 0 ; z– ) {
for (int y = 10; y >= 0 ; y–){
cout << “El ciclo for para la variable Z comienza en ” << y << endl;

}
}
return 0;
}

# Random Code

--Originally published at My awesome Blog!

Heres a code i was doing with some friends just for fun

#include <iostream>
using namespace std;

int main (){
int pant;
float precio, desc, total, final;
cout << “¿Cual es el valor del pantalon? ” << endl;
cin >> precio;
cout << “¿Cual es la cantidad de pantalones comprados? ” << endl;
cin >> pant;
total = precio * pant;
if (pant >= 5)
{
cout << “Tiene un descuento del 25% por la compra de 5 o mas pantalones ” << endl;
desc = (25 * total) / 100;
final = total – desc;
cout << “El monto total a pagar es: ” << final << endl;
}
else
{
cout << “Tiene un descuento del 10% ” << endl;
desc = (10 * total) / 100;
final = total – desc;
cout << “El monto total a pagar es: ” << final << endl;
}
return 0;
}

# Volume of a piramid

--Originally published at My awesome Blog!

Here is a code that help to give me an idea for our final project.
its about a volume of a piramid

#include <iostream>
// Este programa saca el volumen de una piramide con base rectangular, pide los datos al usuario (lado 1 lado 2 (area de la base) y la altura) y realiza las opereciones necesarias
using namespace std;

int main()
{
cout << “Escribe el lado 1 de la piramide en metros.” << endl;