"
Bigint.cpp: In Function 'Bigint operator+(const Bigint&, const Bigint&)':
Bigint.cpp:88: error: 'addition' was not declared in this scope
"
Can anyone please offer assistance as to why addition cannot be accessed?
also, if you see anything else wrong with the code which may be of usefulness to me, please say
thankyou!
#include "Bigint.h"
#include <iostream>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <sstream>
using namespace std;
void Bigint::sToArray(Bigint& n){ // sets array elements to 0, then right aligns
int length_; // the input number within the array
for(int i = 0; i < 256; i ++){
n.num[i]=0;
}
n.length_ = n.text.length();
for(int i = 255; i >= 255-n.length_ ; i --){
n.num[i] = n.text[i] - '0';
}
}
string Bigint::getResult(Bigint& n){
return n.result;
}
void Bigint::arrayToS(Bigint& n){ //turns an array to a string
string result;
ostringstream ss;
for(int i = 0; i < 256 ; i++){
if(n.answer[i] != 0 || n.answer[i] == 0 && n.answer[i-1] != 0){
ss << n.answer[i];
}
}
n.result = ss.str();
}
Bigint Bigint::addition(Bigint& n1, Bigint& n2){
Bigint res("");
int tempAns;
for(int i = 255; i >= 0; i--) {
res.tempAns = n1.num[i] + n2.num[i] + res.carry;
if(res.tempAns>9){
res.carry = 1;
res.tempAns = res.tempAns%10;
}else{
res.carry = 0;
}
res.answer[i] = res.tempAns;
}
arrayToS(res);
return res;
}
Bigint::Bigint(string s){
text = s;
}
Bigint operator +(const Bigint& n1, const Bigint& n2){
Bigint temp = addition(n1, n2);
return temp;
}
ostream& operator <<(std::ostream& out, const Bigint& n){
string text;
out << n.text;
return out;
}
istream& operator >>(std::istream& in, Bigint& n){
string text;
in >> n.text;
return in;
}

New Topic/Question
Reply




MultiQuote






|