#include<iostream>
using namespace std;
int main()
{
char input,answer='y';
int count_lowercase=0,percentage=0,counter;
float fp;
while(answer=='y')
{
count_lowercase=0;
percentage=0;
counter=0;
cout<<"input a character : ";
cin>>input;
if(input>='a'&&input<='z')
count_lowercase++;
while(input!='#')
{
cout<<"input a character : ";
cin >> input;
cout << (int) input << ":" << (int)'#' << endl;
if(input>='a'&&input<='z')
count_lowercase++;
if(input=='a'||input=='e'||input=='i'||input=='o'||input=='u')
percentage++;
counter++;
cout << (int) input << ":" << (int)'#' << endl;
}
cout<<count_lowercase<<endl;
fp=percentage/counter*100;
cout<<fp<<endl;
cout<<"do you want to repeat ? [y for yes or any other key to exit]";
cin>>answer;
}
system ("pause");
return 0 ;
}
Hey buddy,
I kept the debugging code included. You can replace the line that I changed with the old line to see what was going wrong.
the statement:
a='a'||'b'||'c';
is executed as follows:
first of all, the assignment operator evaluates the operand on the right. Because the || has higher precedence than the equal operator the operation will become:
(a = (('a'||'b') || 'c'))
Applying a logical operand on chars is applying it on the integral representation (and not even bitwise).
The end result is that your input variable was being reset to 1 in the comparison operation.
I think you should be counting the vowel on the first character as well (except if that's an edge case required or something in the exercise).
The last thing is that your indentation is good, but remember to indent one more level in even more nested loops.