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