-
March 7th, 2009, 01:47 AM
#1
adding two user input arrays
For this program I have to be able to input two positive arrays up to 20 digits long and add them together, I think I have the input part right I am just having difficulty adding the two arrays together and outputting the new sum array...any help or advice would be great, here is what i have so far:
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int count = 0, number;
char first[20], second[20], sum[20];
cout << "Enter the augend: ";
cin >> noskipws >> first[0];
cout << endl;
while( first[count] != '\n')
{
count++ ;
cin >> first[count];
}
for ( number = count-1; number >= 0; number--)
cout << first[number];
cout << endl;
count=0;
cout << "Enter the adden: ";
cin >> noskipws >> second[0];
cout << endl;
while( second[count] != '\n')
{
count++;
cin >> second[count];
}
for(number = count-1; number >= 0; number--)
cout << second[number];
cout << endl;
number=0;
for(number=0;number<20;number++)
{
sum[number] = first[number] + second[number];
}
cout << sum[number];
cout << endl;
return 0;
}
-
March 7th, 2009, 02:30 AM
#2
Re: adding two user input arrays
Stick some code tags on that to preserve indenting.
-
March 7th, 2009, 08:15 AM
#3
Re: adding two user input arrays
For this program I have to be able to input two positive arrays up to 20 digits long and add them together, I think I have the input part right I am just having difficulty adding the two arrays together and outputting the new sum array...any help or advice would be great, here is what i have so far:
Originally Posted by theflash
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int count = 0, number;
char first[20], second[20], sum[20];
cout << "Enter the augend: ";
cin >> noskipws >> first[0];
cout << endl;
while( first[count] != '\n')
{
count++ ;
cin >> first[count];
}
for ( number = count-1; number >= 0; number--)
cout << first[number];
cout << endl;
count=0;
cout << "Enter the adden: ";
cin >> noskipws >> second[0];
cout << endl;
while( second[count] != '\n')
{
count++;
cin >> second[count];
}
for(number = count-1; number >= 0; number--)
cout << second[number];
cout << endl;
number=0;
for(number=0;number<20;number++)
{
sum[number] = first[number] + second[number];
}
cout << sum[number];
cout << endl;
return 0;
}
-
March 7th, 2009, 09:45 AM
#4
Re: adding two user input arrays
Two areas that stick out as problematic:
1) The inputting of the array values... why are you comparing the input to '\n'????
2) The output of the array sums... you are only outputting sum[20], which is beyond the size of the array.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|