Write a complete program from the #include at the top through return 0; } at the bottom.
Define three char variables char1, char2, and char3
(You may also wish to define a result variable).
Have the user enter three lowercase char characters.
(You may assume that the user correctly enters three lowercase characters.)
Compare these three characters and print only the character
that appears first in the alphabet
#include<iostream>
using namespace std;
int main()
{
char char1,char2,char3;
cout<<"Please, enter 3 lowercase char characters: ";
cin>>char1>>char2>>char3;
if(char1<char2&&char1<char3)
{
cout<<char1<<" is first in the alphabet";
}
else if(char2<char1&&char2<char3)
{
cout<<char2<<" is first in the alphabet";
}
else if(char3<char1&&char3<char2)
{
cout<<char3<<" is first in the alphabet";
}
}
Comments
Leave a comment