93: ***(Syntax)*** Make a happy birthday song for user defined name using function
#include <iostream>
using namespace std;
void hbd(string name, int age)
{
cout << "Happy Birthday to " << name << '.' << endl;
cout << "Happy Birthday to " << name << '.' << endl;
cout << "Happy Birthday dear " << name << '.' << endl;
cout << "Happy Birthday to " << name << '.' << endl << endl;
cout << "You are now " << age << " years old" << endl << endl;
}
int main()
{
string name;
int age;
cout << "Enter your name: ";
getline(cin, name);
cout << "Enter your age: ";
cin >> age;
cout << endl;
hbd(name, age);
return 0;
}
You can also write this program as:
#include <iostream>
using namespace std;
void hbd(string name, int age);
int main()
{
string name;
int age;
cout << "Enter your name: ";
getline(cin, name);
cout << "Enter your age: ";
cin >> age;
cout << endl;
hbd(name, age);
return 0;
}
void hbd(string name, int age)
{
cout << "Happy Birthday to " << name << '.' << endl;
cout << "Happy Birthday to " << name << '.' << endl;
cout << "Happy Birthday dear " << name << '.' << endl;
cout << "Happy Birthday to " << name << '.' << endl << endl;
cout << "You are now " << age << " years old" << endl << endl;
}
Comments
Post a Comment