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;
}
#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;
}
Comments
Leave a comment