In: Computer Science
#include <iostream>
#include <string>
using namespace std;
int main ()
{
//declarations
string name;
//input
cout <<"Enter your first name" << endl;
cin >> name;
//output
cout << "Hello " << name << "! " << endl;
return 0;
}
int age;
Add the following lines to your program:
cout << “Enter your age” << endl;
cin >> age;
Compile and Run.
What type is age? Describe this type.
float bodyTemp;
Add the lines to input and out your body temperature. Compile and run.
What type is bodyTemp? Describe this type.
Height (hint, use two variables)
Weight
Sex (hint, use the char type)
Last name
Answers to these questions only:
Here is my detailed complete solution to your question. If you have any doubts regarding my answer please tell me in the comments. I would be very happy to help you.
CODE TO COPY:
#include <iostream>
#include <string>
using namespace std;
int main ()
{
//declarations
string name,last_name,g;
int age;
float bodyTemp,height,weight;
char gender;
//input
cout <<"Enter your first name" << endl;
cin >> name;
cout <<"Enter your Last name" << endl;
cin >> last_name;
cout << "Enter your age"<< endl;
cin >> age;
cout << "Please Enter your Body Temperature (in °F)"<<
endl;
cin>> bodyTemp;
cout <<"Enter your Gender (Type M for Male or F for Female or
O for Others )" << endl;
cin >> gender;
cout <<"Enter your Height (in centimeters)" <<
endl;
cin >> height;
cout <<"Enter your Weight (in Kgs)" << endl;
cin >> weight;
if (gender == 'M')
g = "Male";
else if (gender == 'F')
g = "Female";
else
g = "Others";
//output
cout << "Hello " << name <<"
"<<last_name<< "! " << endl;
cout << "Your Age is : "<< age << endl;
cout << "Your Body Temperature is :
"<<bodyTemp<<"°F"<< endl;
cout << "Your Gender is : "<< g <<endl;
cout << "Your Height is : "<< height <<"
cm"<<endl;
cout << "Your Weight is : "<< weight <<"
kg"<<endl;
return 0;
}
SCREENSHOT OF CODE:
SCREENSHOT OF OUTPUT 1:
SCREENSHOT OF OUTPUT 2:
cin statement is used to take input from the user through the keyboard.
cout statement is used to print out the output on the screen.
'name' is a variable of data-type string that stores a string of characters.
name is of string data-type.
age is of integer type(int) because age will always be an integer number. This data-type can store integer numbers without decimals.
body temperature is of the float data type. Float data-type can store floating-point numbers up to 2 decimals.
//Answers to these questions only:
int is the name of the data type for storing integers. It is declared as - int variable_name. For example, int age.
an integer data type can be used where you want to store a number.
real data type or floating data type is used to store a numerical value with decimals. It is declared as float variable_name. For example, float temparature.
real data type is used to store height, weight, temperature.
string data type is used to store text written within single-quotes or double-quotes. It is declared as string variable_name. For example, string name.
string data type is used to store names, address etc.
boolean data type is used to check whether the condition is true or false as it stores only 2 values true or false. It is declared as bool b = True or bool a = 10