Some basic reasons to start

Write your question here.
I have started on a question that allowed me to compile but when I went to run it using cygwin or netbeans the program ran and ran without stopping, I had to shut the program down to get it to stop.
1) What causes that type of an issue?
2) I have been trying to get this code working and I either get 0 which is what I initialized 'count' to or I get 99. What causes the value to be 99?
3) How do I fix my code to not show 0 (yes I can get it to read 99 but that isn't helpful either) :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main ()	{		
	ifstream in ("CircleArea.cpp"); // Open for reading
	
		int count = 0;	
		string circle, word;

	while(in >> word) {		
		if(word == circle) //look for the word circle
			count++;
	}
	cout << "The number of times circle is used in the file is "<< count <<endl; //display result of count
}
Your variable circle is not initialized (so it defaults to the empty string).

I think you meant:
13
14
15
16
	while (in >> word) {
		if(word == "circle") //look for the word circle
			count++;
	}

Hope this helps.
You didn't get an infinite loop or the value 99 from the program as you've displayed it here. You must be thinking of previous versions. This version will always print 0 since circle is the empty string and in >> word will never set word to an empty string.
Thank you both:
I didn't realize I needed the "" around circle since I had typed string circle earlier.
I was getting 0 in this version but I was wanting to know why I would get 99 or an infinite loop as I have seen that before.
You could get 99 (or any number) if you forgot to initialize count to 0. There are probably other ways it could have happened so you would have to post the exact code for that.

You can get an infinite loop in many different ways, too, so you would have to post the exact code that was causing it.
Topic archived. No new replies allowed.