Thread: What's this output?

  1. #1
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001

    What's this output?

    Now don;t yell at me for rehashing my question from an earlier post, but what does the #ind00 output of this program mean? I instructed it to display a long double.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  2. #2
    Registered User
    Join Date
    Aug 2002
    unless you post the code i will not be able to give you a better answer then this but my best guess would be that you did not proparly initialize the pi variable and then add to it instead of setting it equal to something.

    It could also be something in the way you output it or perhaps something completely else but my experiance with simaliar output is that you forgot to initialize....

  3. #3
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    The output code is at the bottom of main():
    The code is commented for my Math teacher; just ignore
    // Pi.cpp : Defines the entry point for the console application.
    #define NULL 0x0	//Telling the computer what zero is... because it doesn't know
    #include "stdafx.h" //Includes a file into this project that includes MORE files into this project!
    using namespace std;
    class coord
    	coord(){x = NULL; y = NULL;}
    	long double x;
    	long double y;
    long double lDpow(long double base,int power);
    int main(int argc, char* argv[])
    	coord point;				//Point to be calculated
    	unsigned int r;				//The radius of the circle
    	coord* Points = new coord[3];//Pointer to array of points that is the circle
    	int PointsPosition = 0;		//Current empty slot in the coord array, declared above
    	double inc = 1;				//the incrament at which x values will be calculated
    	long double circ = NULL;	//A quarter of the cirumfrence of our circle
    	bool FileOut = false;
    	std::cout.setf(std::ios::showpoint | std::ios::fixed);//Setup i/o parameters
    	//These next i/o calls prompt the user for information, and take it from the user.
    	std::cout << "Please input the length of the radius: ";
    	std::cin >> r;
    	std::cout << endl;
    	std::cout << "Please input the resolution of the x values\n (Smaller yeilding more accuracy, .001 to 100): ";
    	std::cin >> inc;
    	std::cout << endl;
    	//This next loop loops through incrimental 'x' values, finding their 'y' couterparts
    	for(long double loop = 0; loop <= r; loop += inc)
    		point.y = sqrtl( (r * r) - (loop * loop));	//Set y value  using the x value, radius and centerpoint (0,0)
    		point.x = loop;		//The x value changes with every cycle of the loop by an incrament of inc.
    		Points[PointsPosition] = point;//Pass value from the temporary variable to the one that will be used to calculate cirumfrence.
    		if(loop > 0)	//if the loop has run twice or more
    			circ += sqrtl(lDpow((Points[PointsPosition].x  -  Points[PointsPosition - 1].x),2)  +  lDpow((Points[PointsPosition].y - Points[PointsPosition - 1].y),2));  
    			//(above) add to the circumfrence a value equal to the distance between the two most recent points calculated.
    		PointsPosition++;	//Update the variable that keeps track of what slot we are in in the Points[] array (add 1).
    		 //This brilliant little feature below is what allows gigabytes of information to be calculated while only using about 10 bytes. 
    		if(PointsPosition == 2)		//If the next slot to be written into is the THIRD slot
    			Points[0] = Points[1];	 //these two lines basically reset the array, so we're recycling memory
    			PointsPosition = 1;
    	}//the end of the loop statement
    	//output all of out data to the user!
    	//Remember, only 1/4 of the circumfrence of a circle was calculated, so we must multiply by four.
    	std::cout << "The circumfrence of your circle (rounded): " << circ*4 << endl;
    	std::cout << "Pi, according to your circle (c / 2r): " << std::setprecision(25) << ((circ*4) / (r*2)) << endl;
    	delete[] Points;
    	std::cout << endl << "Press any key and enter to exit";
    	std::cin >> inc;
    	return 0;
    long double lDpow(long double base,int power)
    	long double Answer = 1.00;
    	for(int x = 0; x < power; x++)
    		Answer *= base;
    	return Answer;
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. code output...
    By roaan in forum C Programming
    Replies: 6
    Last Post: 07-03-2009, 02:22 AM
  2. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:08 PM
  3. Replies: 4
    Last Post: 11-30-2005, 04:44 PM
  4. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 05:10 PM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 05:27 AM