<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://mywikibiz.com/index.php?action=history&amp;feed=atom&amp;title=Directory%3ADerek_Elder%2FPrograms%2FReadBigInt</id>
	<title>Directory:Derek Elder/Programs/ReadBigInt - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://mywikibiz.com/index.php?action=history&amp;feed=atom&amp;title=Directory%3ADerek_Elder%2FPrograms%2FReadBigInt"/>
	<link rel="alternate" type="text/html" href="https://mywikibiz.com/index.php?title=Directory:Derek_Elder/Programs/ReadBigInt&amp;action=history"/>
	<updated>2026-06-19T13:15:43Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.3</generator>
	<entry>
		<id>https://mywikibiz.com/index.php?title=Directory:Derek_Elder/Programs/ReadBigInt&amp;diff=51323&amp;oldid=prev</id>
		<title>Derek Elder: Start of page</title>
		<link rel="alternate" type="text/html" href="https://mywikibiz.com/index.php?title=Directory:Derek_Elder/Programs/ReadBigInt&amp;diff=51323&amp;oldid=prev"/>
		<updated>2007-11-01T22:06:32Z</updated>

		<summary type="html">&lt;p&gt;Start of page&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;fstream&amp;gt;&lt;br /&gt;
#include &amp;lt;string&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
&lt;br /&gt;
const int MAX = 5/*0*/;&lt;br /&gt;
&lt;br /&gt;
struct BigInt&lt;br /&gt;
{&lt;br /&gt;
	int Digits[MAX];&lt;br /&gt;
	int numDigits;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
bool ReadBigInt(BigInt&amp;amp; num);&lt;br /&gt;
//Purpose:Read a BigInt, deposit into a string and convert from characters to numeric data&lt;br /&gt;
//Precondition:None.&lt;br /&gt;
//Postcondition:1.Array is populated, data is valid.&lt;br /&gt;
//              2.BigInt is too large, loops until an Int is entered that is small enough.&lt;br /&gt;
void PrintBigInt(const BigInt&amp;amp; num);&lt;br /&gt;
//Purpose:Print a BigInt in the same way it was entered by reversing the way it was stored into the array.&lt;br /&gt;
//Precondition:BigInt num is valid.&lt;br /&gt;
//Postcondition:Data is printed on screen matching the way it was entered from the console.&lt;br /&gt;
bool AddBigInts(const BigInt&amp;amp; num1, const BigInt&amp;amp; num2, BigInt&amp;amp; sum);&lt;br /&gt;
//Purpose:Add two integers together into a sum.&lt;br /&gt;
//Precondition:BigInts num1 and num2 are valid.&lt;br /&gt;
//Postcondition:1.Return true if sum is valid.&lt;br /&gt;
//				2.Return false if there is overflow.&lt;br /&gt;
void firstIntegerLarger(const BigInt&amp;amp; largest, const BigInt&amp;amp; smallest, BigInt&amp;amp; sum);&lt;br /&gt;
//Purpose:Modularize AddBigInts function to make it more efficent.&lt;br /&gt;
//Precondition:BigInts num1 and num2 have been entered and contain good data.&lt;br /&gt;
//Postcondition:1.Sum has been populated by good data as long as num.numDigits &amp;lt;= MAX.&lt;br /&gt;
//				2.If there is overflow (num.numDigits &amp;gt; MAX) it will be indicated in AddBigInts.&lt;br /&gt;
&lt;br /&gt;
void main()&lt;br /&gt;
{&lt;br /&gt;
	BigInt x,y,sum;&lt;br /&gt;
	bool moreNumbers = true;&lt;br /&gt;
	char update = ' ';&lt;br /&gt;
&lt;br /&gt;
	while(moreNumbers)&lt;br /&gt;
	{&lt;br /&gt;
		ReadBigInt(x);&lt;br /&gt;
		ReadBigInt(y);&lt;br /&gt;
		cout&amp;lt;&amp;lt;&amp;quot;The BigInt entered is: &amp;quot;;&lt;br /&gt;
		PrintBigInt(x);&lt;br /&gt;
		cout&amp;lt;&amp;lt;&amp;quot;The BigInt entered is: &amp;quot;;&lt;br /&gt;
		PrintBigInt(y);&lt;br /&gt;
		AddBigInts(x,y,sum);&lt;br /&gt;
		cout&amp;lt;&amp;lt;&amp;quot;The sum is: &amp;quot;;&lt;br /&gt;
		PrintBigInt(sum);&lt;br /&gt;
&lt;br /&gt;
		cout&amp;lt;&amp;lt;&amp;quot;Do you want to add more numbers? (Y or N): &amp;quot;;&lt;br /&gt;
		cin&amp;gt;&amp;gt;update;&lt;br /&gt;
		cin.ignore(50,'\n');&lt;br /&gt;
		cout&amp;lt;&amp;lt;&amp;quot;===========================================&amp;quot;&amp;lt;&amp;lt;endl;&lt;br /&gt;
&lt;br /&gt;
		if(update == 'Y' || update == 'y')&lt;br /&gt;
		{&lt;br /&gt;
			moreNumbers = true;&lt;br /&gt;
		}&lt;br /&gt;
		else&lt;br /&gt;
		{&lt;br /&gt;
			moreNumbers = false;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	cout&amp;lt;&amp;lt;&amp;quot;Program Terminated on request.&amp;quot;&amp;lt;&amp;lt;endl;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
bool ReadBigInt(BigInt&amp;amp; num)&lt;br /&gt;
{&lt;br /&gt;
	int len = 0;&lt;br /&gt;
	char ch = ' ';&lt;br /&gt;
	int counter = 0;&lt;br /&gt;
	bool tooBig = false;&lt;br /&gt;
	string str = &amp;quot;&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
	while(!tooBig) //Initialize tooBig, if integer is too big loop until BigInt entered is valid.&lt;br /&gt;
	{&lt;br /&gt;
		cout&amp;lt;&amp;lt;&amp;quot;Enter an integer: &amp;quot;;&lt;br /&gt;
		getline(cin,str);&lt;br /&gt;
&lt;br /&gt;
		len = (int)str.length(); //Length of the string entered into len&lt;br /&gt;
&lt;br /&gt;
		if (len &amp;gt; MAX)&lt;br /&gt;
		{&lt;br /&gt;
			cout&amp;lt;&amp;lt;&amp;quot;The number you entered is too big, try again!&amp;quot;&amp;lt;&amp;lt;endl;&lt;br /&gt;
			tooBig = false;&lt;br /&gt;
		}&lt;br /&gt;
		else&lt;br /&gt;
		{	&lt;br /&gt;
			num.numDigits = len;&lt;br /&gt;
&lt;br /&gt;
			for(int i = len-1; i &amp;gt;= 0; i--)             //Reverse the string and position of numbers&lt;br /&gt;
			{&lt;br /&gt;
				ch = str[i];                        //Convert from char to numeric value&lt;br /&gt;
				num.Digits[counter] = ch - '0';     //char c = '2';&lt;br /&gt;
				counter++;			    //int n = c - '0';&lt;br /&gt;
			}&lt;br /&gt;
			tooBig = true;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	return true;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void PrintBigInt(const BigInt&amp;amp; num)&lt;br /&gt;
{&lt;br /&gt;
	int counter = num.numDigits - 1;&lt;br /&gt;
&lt;br /&gt;
	if(num.numDigits &amp;gt; MAX)&lt;br /&gt;
	{&lt;br /&gt;
		cout&amp;lt;&amp;lt;&amp;quot;OVERFLOW&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		for(int i = 0; i &amp;lt; num.numDigits; i++)&lt;br /&gt;
		{&lt;br /&gt;
			cout&amp;lt;&amp;lt;num.Digits[counter];&lt;br /&gt;
			counter--;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
	cout&amp;lt;&amp;lt;endl;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
bool AddBigInts(const BigInt&amp;amp; num1, const BigInt&amp;amp; num2, BigInt&amp;amp; sum)&lt;br /&gt;
{&lt;br /&gt;
	if(num1.numDigits &amp;gt;= num2.numDigits)&lt;br /&gt;
	{&lt;br /&gt;
		firstIntegerLarger(num1, num2, sum);&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		firstIntegerLarger(num2, num1, sum);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	//If Overflow return false, otherwise return true&lt;br /&gt;
	if(sum.numDigits &amp;gt; MAX)&lt;br /&gt;
	{&lt;br /&gt;
		return false;&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		return true;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void firstIntegerLarger(const BigInt&amp;amp; largest, const BigInt&amp;amp; smallest, BigInt&amp;amp; sum)&lt;br /&gt;
{&lt;br /&gt;
	int i;&lt;br /&gt;
	int remainder = 0;&lt;br /&gt;
&lt;br /&gt;
	for(i = 0; i &amp;lt; smallest.numDigits; i++)&lt;br /&gt;
	{&lt;br /&gt;
		sum.Digits[i] = largest.Digits[i] + smallest.Digits[i] + remainder;&lt;br /&gt;
&lt;br /&gt;
		if(sum.Digits[i] &amp;gt;= 10)&lt;br /&gt;
		{&lt;br /&gt;
			sum.Digits[i] = (sum.Digits[i] - 10);&lt;br /&gt;
			remainder = 1;&lt;br /&gt;
		}&lt;br /&gt;
		else&lt;br /&gt;
		{&lt;br /&gt;
			remainder = 0;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	for(; i &amp;lt; largest.numDigits; i++)&lt;br /&gt;
	{&lt;br /&gt;
		sum.Digits[i] = largest.Digits[i] + remainder;&lt;br /&gt;
&lt;br /&gt;
		if(sum.Digits[i] &amp;gt;= 10)&lt;br /&gt;
		{&lt;br /&gt;
			sum.Digits[i] = (sum.Digits[i] - 10);&lt;br /&gt;
			remainder = 1;&lt;br /&gt;
		}&lt;br /&gt;
		else&lt;br /&gt;
		{&lt;br /&gt;
			remainder = 0;&lt;br /&gt;
		}	&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	if(i == largest.numDigits &amp;amp;&amp;amp; remainder == 1)&lt;br /&gt;
	{&lt;br /&gt;
		sum.Digits[i] = 1;&lt;br /&gt;
		sum.numDigits = largest.numDigits + 1;&lt;br /&gt;
	}&lt;br /&gt;
	else&lt;br /&gt;
	{&lt;br /&gt;
		sum.numDigits = largest.numDigits;&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Derek Elder</name></author>
	</entry>
</feed>