Challenge: Profile Card
Completed
Create these variables: a string name Riya, an int age 21 and a double height 1.65. Then print them like this:
Name: Riya Age: 21 Height: 1.65
Input
None.
Output
The three lines above.
Example
Output
Name: Riya Age: 21 Height: 1.65
Editor
C++
Hints
#include <string> to use string.
Print the label in quotes, then the variable without quotes.
Solution explanation
Each variable has a type that fits its value: text, a whole number and a decimal.
Show solution
#include <iostream>
#include <string>
using namespace std;
int main() {
string name = "Riya";
int age = 21;
double height = 1.65;
cout << "Name: " << name << "\n";
cout << "Age: " << age << "\n";
cout << "Height: " << height << "\n";
return 0;
} Output
Answer
You can practice without logging in. Log in to save completion.
Save your progress
You're practising as a guest, so your progress won't be saved.
- Track every lab you complete
- Earn verifiable lab certificates
- See your progress in every module