Skip to content

Instantly share code, notes, and snippets.

@midned
Created December 13, 2013 00:45
Show Gist options
  • Save midned/7938274 to your computer and use it in GitHub Desktop.
Save midned/7938274 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char* argv[]) {
int opcion;
int numero;
int promedio;
int total;
vector<int> numeros;
vector<int>::iterator iterator;
do {
cout << "------------------------" << endl;
cout << "Programita: " << endl;
cout << "\t1- Cargar 10 numeros" << endl;
cout << "\t2- Promedio de los 10 numeros" << endl;
cout << "\t3- Suma de los 10 numeros" << endl;
cout << "\t0- Salir" << endl;
cin >> opcion;
switch (opcion) {
case 1:
for (short i = 1; i <= 10; i++) {
cout << "Ingrese numero " << i << ": " << endl;
cin >> numero;
numeros.push_back(numero);
}
break;
case 2:
if (numeros.empty()) {
cout << "No se han cargado numeros" << endl;
}
else {
promedio = 0;
for (iterator = numeros.begin(); iterator < numeros.end(); iterator++) {
promedio += *iterator;
}
promedio /= 10;
cout << "Promedio: " << promedio << endl;
}
break;
case 3:
if (numeros.empty()) {
cout << "No se han cargado numeros" << endl;
}
else {
total = 0;
for (iterator = numeros.begin(); iterator < numeros.end(); iterator++) {
total += *iterator;
}
cout << "Suma total: " << total << endl;
}
break;
default:
if (opcion != 0) {
cout << "Opción incorrecta" << endl;
}
}
} while(opcion != 0);
cout << "¡Adios!" << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment