I have done quite a bit of research about this error on the internet. It seems as if the common answer is that there are either extra brackets somewhere of that I am trying to define my variable in some incorrect ways. I checked my brackets and they seem fine to me and I moved all my variables outside the main function. The error occurs when I try to use density for the first time. This is in line 61. The code is not complete yet because I'm trying to find errors as I go instead of ending up with an overwhelming amount when the code is complete. Any help or advice is appreciated, thank you greatly.
//-------------------------------------------\\
// Purpose: Display a sequence of numbers
// caculated by given equations and a user
// defined starting point. Also calculate
// various stats about the generated numbers.
// Name: Will Beeler
// Date: October 22, 2009
//-------------------------------------------\\
#include <iostream>
#include <cctype>
usingnamespace std;
int firstInteger;
int integer;
int densitySpreadTermCount(0);
double densitySpreadSum(1);
double density;
int integerCount(1);
int main()
{
//prompt user for initial number
cout << "Enter the initial positive integer: ";
cin >> firstInteger;
firstInteger = integer;
//determine if number is even, odd, or 1
dowhile ( integer != 1 )
{
if ( integer % 2 == 0 )
{
integer = integer / 2;
}
else
{
integer = (3 * integer) + 1;
}//end if
// counts total number of integers in sequence
integerCount++;
//cout << integer << " "; ???
/*A continuous sum going with a counter for numbers equal to or less then the
starting value to calculate density spread */
if ( integer <= firstInteger )
{
densitySpreadSum += integer;
densitySpreadTermCount++;
}//if
}//while
density = ( densitySpreadSum + 1 ) / ( densitySpreadTermCount + 1);
cout << "Density: " << density << endl;
return 0;
}
Ha. Wow. Perfect answer. I completely missed that. I had been changing back an forth in between the two and apparently forgot to delete the do after copy pasting the while. Thank you very much (both of you), fixed the problem right up.