Write a C++ program to obtain the given output:
Enter any number or enter 0 to exit: 8
Enter your choice, star[s] and hash[h]: h
########
Enter any number or enter 0 to exit: 4
Enter your choice, star[s] and hash[h]: s
****
Enter any number or enter 0 to exit: 0
Are you sure you want to exit? (Y/N): Y
Thank you for using this program. Have a good luck!
Press any key to continue . . .
#include<iostream>
using namespace std;
int main()
{
int n;
char option,opt;
cout<<"Enter any number or enter 0 to exit: ";
cin>>n;
if(n==0){
cout<<"Are you sure you want to exit? (Y/N"<<endl;
cin>>opt;
if(opt=='Y'||opt=='y'){
cout<<"Thank you for using this program. Have a good luck!"<<endl;
}
else if(opt=='N'||opt=='n'){
cout<<"Enter any number or enter 0 to exit: ";
cin>>n;
if(n==0){
cout<<"Are you sure you want to exit? (Y/N"<<endl;
cin>>opt;
if(opt=='Y'||opt=='y'){
cout<<"Thank you for using this program. Have a good luck!"<<endl;
}
else if(opt=='N'||opt=='n'){
cout<<"Enter any number or enter 0 to exit: ";
cin>>n;
if(n==0){
cout<<" ";
}
else{
cout<<"Enter your choice, star[s] and hash[h]: ";
cin>>option;
if(option=='h'|| option=='H'){
cout<<"#######"<<endl;
}
else if(option=='s'||option=='S'){
cout<<"*******"<<endl;
}
}
}
}
else{
cout<<"Enter your choice, star[s] and hash[h]: ";
cin>>option;
if(option=='h'|| option=='H'){
cout<<"#######"<<endl;
}
else if(option=='s'||option=='S'){
cout<<"*******"<<endl;
}
}
}}
else{
cout<<"Enter your choice, star[s] and hash[h]: ";
cin>>option;
if(option=='h'|| option=='H'){
cout<<"#######"<<endl;
cout<<"Enter any number or enter 0 to exit: ";
cin>>n;
if(n==0){
cout<<"Are you sure you want to exit? (Y/N"<<endl;
cin>>opt;
if(opt=='Y'||opt=='y'){
cout<<"Thank you for using this program. Have a good luck!"<<endl;
}
else if(opt=='N'||opt=='n'){
cout<<"Enter any number or enter 0 to exit: ";
cin>>n;
if(n==0){
cout<<" ";
}
else{
cout<<"Enter your choice, star[s] and hash[h]: ";
cin>>option;
if(option=='h'|| option=='H'){
cout<<"#######"<<endl;
}
else if(option=='s'||option=='S'){
cout<<"*******"<<endl;
}
}
}
}
else{
cout<<"Enter your choice, star[s] and hash[h]: ";
cin>>option;
if(option=='h'|| option=='H'){
cout<<"#######"<<endl;
}
else if(option=='s'||option=='S'){
cout<<"*******"<<endl;
}
}
}
else if(option=='s'||option=='S'){
cout<<"*******"<<endl;
cout<<"Enter any number or enter 0 to exit: ";
cin>>n;
if(n==0){
cout<<"Are you sure you want to exit? (Y/N"<<endl;
cin>>opt;
if(opt=='Y'||opt=='y'){
cout<<"Thank you for using this program. Have a good luck!"<<endl;
}
else if(opt=='N'||opt=='n'){
cout<<"Enter any number or enter 0 to exit: ";
cin>>n;
if(n==0){
cout<<" ";
}
else{
cout<<"Enter your choice, star[s] and hash[h]: ";
cin>>option;
if(option=='h'|| option=='H'){
cout<<"#######"<<endl;
}
else if(option=='s'||option=='S'){
cout<<"*******"<<endl;
}
}
}
}
else{
cout<<"Enter your choice, star[s] and hash[h]: ";
cin>>option;
if(option=='h'|| option=='H'){
cout<<"#######"<<endl;
}
else if(option=='s'||option=='S'){
cout<<"*******"<<endl;
}
}
}
}
}
Comments
Leave a comment