-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04-user-input.cpp
More file actions
34 lines (25 loc) · 973 Bytes
/
04-user-input.cpp
File metadata and controls
34 lines (25 loc) · 973 Bytes
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
#include <iostream>
using namespace std;
int main() {
int age;
double gpa;
char grade;
string name;
// Nota: "cout" representa la salida estandar que, por defecto, es la consola.
// Nota: "cin" representa la entrada estandar que, por defecto, es el teclado.
cout << "Enter your age: ";
cin >> age;
cout << "Enter your gpa: ";
cin >> gpa;
cout << "Enter your grade: ";
cin >> grade;
cin.ignore(); // Ignoramos el salto de línea del buffer para no afectar a la lectura del string siguiente.
cout << "Enter your name: ";
//cin >> name; // Solo lee hasta el primer espacio o hasta pulsar ENTER.
getline(cin, name); // Si queremos leer un string con espacios, tenemos que usar esta función "getline".
cout << "You are " << age << " years old." << endl;
cout << "Your gpa is: " << gpa << endl;
cout << "Your grade is: " << grade << endl;;
cout << "Your name is: " << name;
return 0;
}