439,798 views
1 vote
1 vote
Write a program that:

stores your name in one variable called name
stores your age in another variable called age
prints a one-line greeting that includes your name and your age.
Your program should output something like this:

Hi! My name is Arthur and I am 62 years old.

Hint: Do not get user input for the values of name and age but instead simply save these values inside your program as static variables, or variables that do not change value.

User Sushant Verma
by
2.9k points

1 Answer

21 votes
21 votes

Answer:

#include<iostream>

#include<string>

using namespace std;

int main() {

const string name = "Arthur";

const int age = 68;

cout<<"Hey my name is "<<name<<" and my age is "<<age;

return 0;

}

Step-by-step explanation:

Above is the c++ program for printing one line greeting that includes your name and your age.

String library is used to save name in constant string variable "name"

and age is stored in constant integer type age variable then both of them are printed using cout (ostream object) build in iostream library.

Program output has been attached below.

Write a program that: stores your name in one variable called name stores your age-example-1
User FLUXparticle
by
2.9k points