From 290ced42d1314ef3cc299dc0f7c5473a267599e8 Mon Sep 17 00:00:00 2001 From: Christoph Fuerst Date: Sun, 26 Mar 2017 20:22:33 +0200 Subject: [PATCH] Added menu dialog --- src/primefactors.cpp | 103 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 68 insertions(+), 35 deletions(-) diff --git a/src/primefactors.cpp b/src/primefactors.cpp index 7de4e33..45a1498 100644 --- a/src/primefactors.cpp +++ b/src/primefactors.cpp @@ -100,45 +100,78 @@ void factor_int2(mpz_class N) cout << "Found prime-factors: " << (a-b)/2 << " and " << ((a+b-2)/2) << endl; } -int main() +int main(int argc, char** argv) { - mpz_class N; - mpz_class *trialdivisors, *factors; - unsigned long max; - unsigned long nooffactors; - - cout << "Enter Integer to be factored.... "; - cin >> N; - cout << endl; - - max = (unsigned long)(sqrt(N.get_ui())); - - trialdivisors = new mpz_class[max]; - factors = new mpz_class[max]; - - trialdivisors[0] = 2; - trialdivisors[1] = 3; - trialdivisors[2] = 5; - for(unsigned int i=3;i> input; + cout << endl; + }while((input != 'A') && (input != 'C') ); + + switch(input) + { + case 'A': + { + cout << "Select Trial divison" << endl; + mpz_class N; + mpz_class *trialdivisors, *factors; + unsigned long max; + unsigned long nooffactors; + + cout << "Enter Integer to be factored.... "; + cin >> N; + cout << endl; + + max = (unsigned long)(sqrt(N.get_ui())); + + trialdivisors = new mpz_class[max]; + factors = new mpz_class[max]; + + trialdivisors[0] = 2; + trialdivisors[1] = 3; + trialdivisors[2] = 5; + for(unsigned int i=3;i> N; + cout << endl; + factor_int2(N); + break; + } + default: + break; + } } - factor_int(N, trialdivisors, nooffactors, factors); - - for(unsigned long i=0;i<=nooffactors;i++) - cout << factors[i] << " "; - cout << endl; - - factor_int2(N); - return (0); } -- 2.1.4