I'm trying to make a program that asks the user to input characters untill '@' is inserted and at the end it should show biggest small letter, capital letter and digit as well as how many of each were inserted. Here's what I tried:
#include <iostream>
int main()
{
char a; //character that user has to insert
std::cin>>a;
char small=a;
char big=a;
char digit=a;
int i=0,j=0,k=0; //counters for small letters, capital letters and digits
while (a!='@')
{
if (a>='a' || a<='z')
{
if (a>small)
{
small=a; //grabs the biggest small letter
}
i++;
}
else if (a>='A' || a<='Z')
{
if (a>big)
{
big=a; //grabs the biggest capital letter
}
j++;
}
else if (a>='0' || a<='9')
{
if (a>digit)
{
digit=a; //grabs the biggest digit
}
k++;
}
std::cin>>a;
}
std::cout<<small<<'\t'<<i<<std::endl;
std::cout<<big<<'\t'<<j<<std::endl;
std::cout<<digit<<'\t'<<k<<std::endl;
return 0;
}
When I run this the first if gives me biggest small letter but the counter doesn't only count characters whitin the (a>='a' || a<='z') range, instead it counts everything I insert and the 2 else if statements give me the first character inserted and the counters don't work at all. What am I doing wrong and why doesn't this work?
Aucun commentaire:
Enregistrer un commentaire