Answer to Question #208891 in C++ for she

Question #208891

QUESTION 2

Modify the codes given below so that the program is able to display the number of digits and alphabets entered by the user. Use function to display it.


  #include<iostream>

using namespace std;

int main() {

char input;

for(int counter = 0; counter < 10; counter++) {

      cout<<"Enter a symbol: ";

      cin>>input;

}

return 0; 


1
Expert's answer
2021-06-20T08:12:25-0400
#include<iostream>


using namespace std;
void display(int alphabets,int digits);


int main() {
	char input;
	int alphabets=0;
	int digits=0;
	for(int counter = 0; counter < 10; counter++) {
		cout<<"Enter a symbol: ";
		cin>>input;
		if((input>=65 && input<=90)|| (input>=97 && input<=122)){
			alphabets++;
		}else if(input>=48 && input<=57){
			digits++;
		}
	}
	
	display(alphabets,digits);
	cin>>digits;
	return 0;
}


void display(int alphabets,int digits){
	cout<<"No. alphabets: "<<alphabets<<"\n";
	cout<<"No. digits: "<<digits<<"\n";
}

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