Está en la página 1de 2

#include<cstdlib> #include<ctime> #include<iostream> using namespace std; int nofw; #define N 8 // numero de pares de palabras en la matriz bool checkrep(int

n, int num[]) { for(int i=0; i<nofw; i++) if(n == num[i]) return true; return false; } int main() { srand(time(NULL)); string ans, words[N][2] = {{"hi", "hola"}, {"house", "casa"}, {"water", "agua"}, {"roof", "techo"}, {"chair", "silla"}, {"loudspeaker", "bocina"}, {"screen", "pantalla"}, {"money", "dinero"}}; int n, correct=0, wrong=0; cout << "Numero de palabras?: "; cin >> nofw; // obtener 'nofw' palabras aleatoriamente de nuestra matriz int num[nofw]; for(int i=0; i<nofw; i++) { do n = rand() % N; while(checkrep(n, num)); num[i] = n; cout << words[n][0] << " -> " << words[n][1] << endl; } cin.get(); cin.get(); system("cls"); // preguntar el significado de cada palabra for(int i=0; i<nofw; i++) { cout << words[num[i]][0] << " = "; cin >> ans; if(ans == words[num[i]][1]) { correct++; cout << ">> Bien :)\n\n"; } else { wrong++; cout << ">> Mal :(\n\n"; } } cout << "Tuviste un " << (float)correct / (float)nofw * 100 << "% de respuestas correctas."; cin.get(); cin.get(); }

Expresiones aritmticas
/* Un marathon tiene 26 millas y 385 yardas */ /* Calcula la distancia del marathon en Kilmetros */ /* Una milla tiene 1760 yardas */ #include <iostream.h> void main (void){ int millas,yardas; float kilometros; millas = 26; yardas = 385; /* frmula de conversin */ kilometros = 1.609 * (millas + yardas / 1760); // salida de datos cout <<"Un marathon tiene "<< kilometros << " kilometros" << endl;

DO WHILE
#include<stdio.h> main() { int a; int b; int suma=0; int respuesta; do { printf("Inserta el primer valor\n"); scanf("%i",&a); printf("Inserta el segundo valor\n"); scanf("%i",&b); suma=a+b; printf("El resultado es: \n %d" ,suma); printf("DESEAS REGRESAR AL PROGRAMA: SI=1\n NO=2\n"); scanf("%i",&respuesta); } while (respuesta==1); return 0; }

También podría gustarte