Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18
  1. #16
    maestro1994's Avatar
    Join Date
    Sep 2015
    Gender
    male
    Posts
    95
    Reputation
    10
    Thanks
    13
    Quote Originally Posted by robater View Post
    Okay, well I tried to do the whole correct location thing. What am I doing wrong now?

    Code:
    #include <iostream>
    #include <vector>
    #include <cctype>
    #include <stdexcept>
    #include <algorithm>
    #include <numeric>
    #include <string>
    #include <functional>
    #include <assert.h>
    #include <sstream>
    using namespace std;
    
    int addition(string input1, string input2, int &result, vector<int> &largeInt1, vector<int> &largeInt2, vector<int> &finalInt);
    
    
    int main() {
    	vector<int> largeInt1 (12, 0); // initialize to zero
    	vector<int> largeInt2 (12, 0); // initialize to zero
    	vector<int> finalInt (13, 0); // initialize to zeros
    
    	int result, flength;
    
    	string input1, input2, results;
    
    	cin >> input1;
    	cin >> input2;
    	for(int i = 0; i < input1.size(); i++) {
    		cout << input1.at(i);
    	}
    
    	for(int i = 0; i < input2.size(); i++) {
    		cout << input2.at(i);
    	}
    	largeInt1.resize(input1.size());
    	largeInt2.resize(input2.size());
    
    	flength = largeInt1.size()+largeInt2.size();
    
    	finalInt.resize(flength);
    	result = addition(input1, input2, result, largeInt1, largeInt2, finalInt);
    
    	stringstream convert;
    	convert << result;
    	results = convert.str();
    
    	cout << "String Conversion is: " << results << endl;
    	for (unsigned i=0; i<input1.length(); ++i)
    		{
    			finalInt[i] = input1.at(i);
    		}
    
    	for(int i = finalInt.size(); i <= 0; i--) {
    		cout << finalInt[i];
    	}
    
    	cin >> flength;
    	return 0;
    }
    
    int addition(string input1, string input2, int &result, vector<int> &largeInt1, vector<int> &largeInt2, vector<int> &finalInt){
    
    	int length, base, last, remainder;
    	bool isOdd;
    
    	for (int i=0; i<input1.length(); ++i)
    	{
    		for(int n = 0; n < 12; n++) {
    		if(input1.at(i)%(n+1)*10 == input1.at(i)) {
    			largeInt1[12-n] = input1.at(i);
    		}
    	}
    	}
    
    	for (int i = 0; i<input2.length(); i++) {
    		for(int n = 0; n < 12; n++) {
    			if(input2.at(i)%(n+1)*10 == input2.at(i)) {
    				largeInt2[12-n] = input2.at(i);
    			}
    	}
    	}
    
    	cout << "Input to LargeInt1: ";
    	for(int i = 0; i < largeInt1.size(); i++) {
    		cout << largeInt1[i] << " ";
    		cout << endl;
    	}
    	cout << endl;
    	cout << "Input to LargeInt2: ";
    	for(int i = 0; i < largeInt2.size(); i++) {
    		cout << largeInt2[i];
    		cout << endl;
    	}
    	cout << endl;
    	length = input1.size()+input2.size();
    	if((length & 1) == 0) {
    	} else {
    		isOdd = true;
    	}
    
    	last = largeInt1.size();
    	for(int i = 0; i <= length; i++) {
    		base = largeInt1[12-i]+largeInt2[12-i];
    		cout << "Base in << " << i << ": " << base << endl;
    		if(base >= 10) {
    			remainder = base-9;
    			finalInt[12-i] = base-remainder;
    			cout << "Remainder in << " << i << ": " << remainder << endl;
    		} else {
    			finalInt[12-i] = base;
    		}
    	}
    cout << "Result is: " << result << endl;
    return result;
    }
    "Why doesn't this work?" "What's wrong with this?" "How can I fix?"
    Did you read what I said?

    So my advice: Run your program in a debugger, statement by statement, and compare what it is doing with what you think it should be doing.

    Not familiar with a debugger yet? Then start to get used to it right away. It is the most important tool you will ever use as a programmer.
    When you know where is the problem, post.

  2. #17
    InunoTaishou's Avatar
    Join Date
    Jan 2009
    Gender
    male
    Location
    The Internet
    Posts
    446
    Reputation
    20
    Thanks
    951
    My Mood
    Relaxed
    Quote Originally Posted by robater View Post
    Okay, well I tried to do the whole correct location thing. What am I doing wrong now?

    Code:
    #include <iostream>
    #include <vector>
    #include <cctype>
    #include <stdexcept>
    #include <algorithm>
    #include <numeric>
    #include <string>
    #include <functional>
    #include <assert.h>
    #include <sstream>
    using namespace std;
    
    int addition(string input1, string input2, int &result, vector<int> &largeInt1, vector<int> &largeInt2, vector<int> &finalInt);
    
    
    int main() {
    	vector<int> largeInt1 (12, 0); // initialize to zero
    	vector<int> largeInt2 (12, 0); // initialize to zero
    	vector<int> finalInt (13, 0); // initialize to zeros
    
    	int result, flength;
    
    	string input1, input2, results;
    
    	cin >> input1;
    	cin >> input2;
    	for(int i = 0; i < input1.size(); i++) {
    		cout << input1.at(i);
    	}
    
    	for(int i = 0; i < input2.size(); i++) {
    		cout << input2.at(i);
    	}
    	largeInt1.resize(input1.size());
    	largeInt2.resize(input2.size());
    
    	flength = largeInt1.size()+largeInt2.size();
    
    	finalInt.resize(flength);
    	result = addition(input1, input2, result, largeInt1, largeInt2, finalInt);
    
    	stringstream convert;
    	convert << result;
    	results = convert.str();
    
    	cout << "String Conversion is: " << results << endl;
    	for (unsigned i=0; i<input1.length(); ++i)
    		{
    			finalInt[i] = input1.at(i);
    		}
    
    	for(int i = finalInt.size(); i <= 0; i--) {
    		cout << finalInt[i];
    	}
    
    	cin >> flength;
    	return 0;
    }
    
    int addition(string input1, string input2, int &result, vector<int> &largeInt1, vector<int> &largeInt2, vector<int> &finalInt){
    
    	int length, base, last, remainder;
    	bool isOdd;
    
    	for (int i=0; i<input1.length(); ++i)
    	{
    		for(int n = 0; n < 12; n++) {
    		if(input1.at(i)%(n+1)*10 == input1.at(i)) {
    			largeInt1[12-n] = input1.at(i);
    		}
    	}
    	}
    
    	for (int i = 0; i<input2.length(); i++) {
    		for(int n = 0; n < 12; n++) {
    			if(input2.at(i)%(n+1)*10 == input2.at(i)) {
    				largeInt2[12-n] = input2.at(i);
    			}
    	}
    	}
    
    	cout << "Input to LargeInt1: ";
    	for(int i = 0; i < largeInt1.size(); i++) {
    		cout << largeInt1[i] << " ";
    		cout << endl;
    	}
    	cout << endl;
    	cout << "Input to LargeInt2: ";
    	for(int i = 0; i < largeInt2.size(); i++) {
    		cout << largeInt2[i];
    		cout << endl;
    	}
    	cout << endl;
    	length = input1.size()+input2.size();
    	if((length & 1) == 0) {
    	} else {
    		isOdd = true;
    	}
    
    	last = largeInt1.size();
    	for(int i = 0; i <= length; i++) {
    		base = largeInt1[12-i]+largeInt2[12-i];
    		cout << "Base in << " << i << ": " << base << endl;
    		if(base >= 10) {
    			remainder = base-9;
    			finalInt[12-i] = base-remainder;
    			cout << "Remainder in << " << i << ": " << remainder << endl;
    		} else {
    			finalInt[12-i] = base;
    		}
    	}
    cout << "Result is: " << result << endl;
    return result;
    }
    Code:
    	largeInt1.resize(input1.size());
    	largeInt2.resize(input2.size());
    Why are you resizing the vectors?

    Code:
    	flength = largeInt1.size()+largeInt2.size();
    
    	finalInt.resize(flength);
    Why is the length of the final int the length of both of the vectors?
    Why are you resizing the finalInt?

    Code:
    int addition(string input1, string input2, int &result, vector<int> &largeInt1, vector<int> &largeInt2, vector<int> &finalInt){
    Why is addition returning an int? If the number is larger than int then this function will not return the correct answer

    I don't even know what your addition function is actually trying to do, but it's completely wrong....

    Code:
    	stringstream convert;
    	convert << result;
    	results = convert.str();
    I don't even know what you're doing here.... You're trying to store a cstring into an int, makes no sense (results was declared as an int)

    Code:
    	for(int i = finalInt.size(); i <= 0; i--) {
    		cout << finalInt[i];
    	}
    ?????????????????????????????

    I want you to do this, here is a very large math problem. Write it down on a piece of paper, nice and neat, line up the columns of both and I want you to add it together.

    _951753456
    +753159456

    Think about this logically, what are you doing when you add the numbers together? Step by step by step by step. Think about where the numbers need to be in in each vector. Think about what happens when the answer of one column is greater than 9 (meaning it's two digits)
    https://www.mpgh.net/forum/signaturepics/sigpic210976_1.gif

  3. #18
    hkKenshin's Avatar
    Join Date
    Oct 2013
    Gender
    male
    Posts
    301
    Reputation
    28
    Thanks
    340
    If you wanna add some really big ass nums, look at the GNU Multi-Precision library. It's used for SSL and all that lovely Cryptographic stuff.
    Basically supports adding numbers as large as the amount of RAm you have.

    For example, it is able to calculate mathematical operations on 4096 bit RSA keys ( Aka a key greater than a 64 bit value like __int64 )

Page 2 of 2 FirstFirst 12

Similar Threads

  1. [Tutorial] How to use a Number Pad hack on a laptop
    By Color in forum CrossFire Tutorials
    Replies: 22
    Last Post: 03-04-2013, 08:16 PM
  2. [Tutorial] How to use a Number Pad hack on a laptop
    By Color in forum Combat Arms Tutorials
    Replies: 9
    Last Post: 11-22-2012, 03:04 AM
  3. Free 11880 Zp (Have to use phone number and call!!)
    By SexyStryker in forum CrossFire Tutorials
    Replies: 10
    Last Post: 11-13-2011, 11:03 PM
  4. [Help] How to use "double" ( you can use numbers like 5.4) in your programs.
    By Ronon666 in forum C++/C Programming
    Replies: 7
    Last Post: 06-18-2011, 02:37 PM
  5. Adding and using Resources with Visual Studios Express
    By why06 in forum C++/C Programming
    Replies: 3
    Last Post: 04-02-2010, 09:08 AM