|
-
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";
}
-
Oct 8th, 2002, 08:34 AM
#2
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.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
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
|