this program should add 2 integers in the range of 20 digits, but only 10 digits are allowed, else the sum would be incorrect. can anyone plz show me what's wrong with my codes? Here's what i got so far....
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
char option=' ' ;
while ( (option != 'Q') and (option != 'q') )
{
cout << "Select : (C)ontinue (Q)uit:" ;
cin >> option ;
switch (option)
{
case 'C' : case 'c': //user chose to continue
{
cout << "Enter number in the range of 1-20 digits: " << endl;
char c[20] ;
cin >> c ;
int x = atoi (c) ; //convert into int
int num[20] ;
for (int i = 0; i < 20; i++)
{
char temp = c[i] ;
num[i] = atoi(&temp) ;
}
cout << "Enter 2nd number in the range of 1-20 digits: " << endl ;
char d[20] ;
cin >> d ;
int y = atoi(d) ;//convert into int
int num2[20] ;
for(int e = 0; e < 20; e++)
{
char temp2 = d[e] ;
num2[e] = atoi(&temp2) ;
}
int total = atoi(c) + atoi(d) ;
cout << "The total is " ;
cout << total << endl;
}
}
}
system("PAUSE");
return EXIT_SUCCESS;
}