- ++Problem 2 by c
#include
#include
using namespace std;
/*Problem #2
Write a program to ask the use to enter his/her name and
print it on screen.*/
//problem analysis
//The program should ask the user to enter his/her name and print it on the screen.
//steps to solve the problem
//1. Start
//2.read the input from the user
//3. print the input
//4. End
//tools to solve the problem
//1.function to read the input from the user
//2.procedure to print the input
//3.function to exit the program
//4.function to clean screen
//slove the problem :
//function to read the input from the user
string read_name()
{
string name;
cout << "Enter your name: ";
getline(cin, name);
return name;
}
;
//procedure to print the input :
void print_name(string name)
{
cout << " \n Your name is : "<< name << endl;
}
//function to exit the program
int exit_program()
{
cout << “Exit the program” << endl;
cin.ignore();
cin.get();
return 0;
}
;
//function to clean screen
int clean_screen()
{
system(“cls”);
return 0;
}
// main function
int main()
{
print_name(read_name());
exit_program();
clean_screen();
return 0;
}
by python
#Copyright© 2022 PROGRAMMING ADVICE Mohammed Abu-Hadhoud
#Problem #2
#Write a program to ask the use to enter his/her name and
#print it on screen.
#steeps to solve the problem:
#step 1: ask the user to enter his/her name
#step 2: print the name on the screen
#sloution by using function :
def print_name ():
name = input (“please inter your name \n” )
print(“your name is :\n” ,name)
print_name()
#sloution without using function:
name = input (“please inter your name \n” )
print(f"your name is :\n" ,{name})