-
how to fix my loop
With the following code i keep getting an infinite loop, im not even sure if the following code is right, but what i am trying to do is have the user type in a sentence, then a letter, and the program finds how many times the letter is entered, how would i accomplish this? thank you
#include <iostream.h>
#include <apstring.h>
void main()
{
apstring sentence;
char letter;
int x;
cout<<"enter a sentence ";
getline(cin,sentence);
cout<<"enter a letter ";
cin>>letter;
x=0;
do
{cout<<sentence.find(letter);
x=x+1;}
while (letter>=0);
cout<<"The letter "<<letter<<" appears "<<x<<" times in the sentence";
}
-
do
{cout<<sentence.find(letter);
x=x+1;}
while (letter>=0);
I don't know exactly how apstring works, but I'm sure it won't alter letter, therefore letter will never be < 0.
Anyway you should use <string> and <iostream> and
using namespace std;
instead of <iostream.h> and <apstring.h>.
iostream.h is deprecated and apstring.h simply is crap.