|
-
Oct 7th, 2002, 04:57 PM
#1
Thread Starter
Junior Member
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";
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|