Answer to Question #262534 in C++ for Vava

Question #262534

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 . . .

1
Expert's answer
2021-11-08T05:31:58-0500
#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;
		}
	}
		}
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS