Answer to Question #208897 in C++ for syahidah

Question #208897

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:11:31-0400
#include<iostream>


using namespace std;


int main()


{


char input;
int digits = 0;
int alphabet =0 ;
//Entry of ten symbols
for(int counter = 0; counter < 10; counter++)


{
//Allowing user to enter symbols
cout<<"Enter a symbol: ";


cin>>input;
	if ((input >= 65 && input<= 90)
        || (input >= 97 && input <= 122)){
        	alphabet ++;
		}
	 else if (input >= 48 && input <= 57)
{
digits ++;	
}
}
cout<<"The number of digits is:\t"<<digits<<"\nThe number of alphabets is:\t"<<alphabet;
return 0;
}

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