-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodigo.cpp
More file actions
94 lines (78 loc) · 2.3 KB
/
Copy pathcodigo.cpp
File metadata and controls
94 lines (78 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include<iostream>
#include<stdlib.h>
#include <vector>
#include <string.h>
#include <limits>
using namespace std;
int main()
{
// Maximo valor permitido para el tipo de dato double.
double min = std::numeric_limits<double>::max();
double gran = std::numeric_limits<double>::min() ;
// int debug =0;
double a;
string b;
int trobat=1;
double conversio; //1m = 100cm, 1in = 2,54cm, 1ft = 12in;
double valor_total=0;
int sumants=0;
vector<double> minim;
cout << "Ejercicio 9, pagina 126" << endl;
cout << "Introduce el numero y sus unidades en ( cm, m, in, ft)" << endl;
while(trobat ==1 )
{
cin.clear();
do{
cout << "Introduce un valor y sus unidades\t:\t";
cin >> a >> b;
}while(isdigit(a) && isalpha(b[0]) );
//if(debug == 1 )
// cout << " a = " << a << " b = " << b;
if(b.find("cm") != string::npos && b.size()==2)
{
conversio = a/(double)100.0;
cout << "la conversion es: " << conversio << " cm" << endl;
minim.push_back(conversio);
}
else if(b.find("m") != string::npos && b.size()==1)
{
conversio = a;
cout << "la conversion es: " << conversio << endl;
valor_total += conversio;
minim.push_back(conversio);
}
else if(b.find("in") != string::npos && b.size()==2)
{
conversio = a*2.54*100;
cout << "la conversion es " << conversio << " in" << endl;
minim.push_back(conversio);
}
else if(b.find("ft") != string::npos && b.size()==2)
{
conversio = a*2.54*100/12;
cout << "\n la conversion es " << conversio << " ft" << endl;
minim.push_back(conversio);
}
else
{
cout << "Esta medida : '" << b << "' no esta soportada" << endl << "Lo siento" << endl;
}
if(b.find("|") != string::npos )
{
trobat =0;
}
else
{
if(conversio<min)
min = conversio;
if(conversio>gran)
gran = conversio;
sumants++;
}
}
cout << "el menor valor de todos: " << min << endl;
cout << "el mayor valor de todos: " << gran << endl;
cout << "numero de valores introducidos: " << sumants << endl;
cout << "suma total= " << valor_total << endl;
return(0);
}