Now with functions

#TC1017 #WSQ08

For this programm I had to go back to WSQ03, which just did some basic operations with two numbers, and step it up a notch by implementing functions.

I really like the way functions work, it might be a little easy lo loose track of what the compiler is doing with all of those variables, but once you get the hang of it it becomes very interesting to see all the things you can doy by passing paramaters onto other functions and using their results for something else.

The only problem I had when programming this was, once again, checking syntax of the functions. Everything else was donde smoothly.

functions.proof

Source code:

#include <iostream>
using namespace std;
double primero, segundo;

double suma (double a, double b)
{
int resultado1 = (a+b);
cout << “El resultado de la suma es: ” << resultado1 << endl;
}

double resta1 (double a, double b)
{
double resultado2 = a-b;
cout << “La resta del primer numero menos el segundo es: ” << resultado2 << endl;
}

double resta2 (double a, double b)
{
double resultado3 = b-a;
cout << “La resta del segundo numero menos el primero es: ” << resultado3 << endl;
}
double producto (double a, double b)
{
double resultado4 = a*b;
cout << “El producto de ambos numeros es: ” << resultado4 << endl;
}

double division1 (double a, double b)
{
double resultado5 = a/b;
cout << “El resultado de el primer numero entre el segundo es: ” << resultado5 << endl;
}

double division2 (double a, double b)
{
double resultado6 = b/a;
cout << “El resultado del segundo numero entre el primero es: ” << resultado6 << endl;
}
int main() {
cout << “Ingrese el valor del primer numero :” << endl;
cin >>


cout << endl;
cout << “Ingrese el valor del segundo numero:” << endl;
cin >> segundo;
cout << endl;

suma (primero, segundo);
resta1 (primero, segundo);
resta2 (primero, segundo);
producto (primero, segundo);
division1 (primero, segundo);
division2 (primero, segundo);

}

————

CC BY-SA 4.0 Now with functions by diegodamy is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.