1
1111111111
Here is what I have so far... User is to enter 2 integers. One digit
at a time. After that I have to print out what the user entered, and
then add the two together. Example:
Enter First Integer (one digit at a time) //-1 ends it
1
2
3
-1
Enter Second Intger (one digit at a time) //-1 ends it
2
3
4
5
6
-1
You entered:
123
&
23456
The sum of these numbers is 23579
//I AM LOST TRYING TO ADD THE TWO TOGETHER....
HERE IS MY CODE.. THANKS FOR HELPING!!!
#include <iostream>
using namespace std;
void display(int x[], int n);
void main() {
int arr[100],num;
int i=0, cnt;
cout << "enter the digits of your first integer (one at a time)"
<<endl;
while(1) {
cin >> num;
if (num !=-1) {
arr=num;
i++;
}
else {
break;
}
}
cnt=i;
int arr1[100],num2;
int j=0, cnt1;
cout << "enter the digits of your second integer (one at a
time)"<<endl;
while(1) {
cin >> num2;
if (num2 !=-1) {
arr1[j]=num2;
j++;
}
else {
break;
}
}
cnt1=j;
//display the results
cout << "you entered the numbers: "<<endl;
display(arr, cnt);
cout<<"and"<<endl;
display(arr1, cnt1);
}
void display(int x[], int n) {
int i;
for (i=0; i<n; i++) {
cout << x;
}
cout << "\n";
}
at a time. After that I have to print out what the user entered, and
then add the two together. Example:
Enter First Integer (one digit at a time) //-1 ends it
1
2
3
-1
Enter Second Intger (one digit at a time) //-1 ends it
2
3
4
5
6
-1
You entered:
123
&
23456
The sum of these numbers is 23579
//I AM LOST TRYING TO ADD THE TWO TOGETHER....
HERE IS MY CODE.. THANKS FOR HELPING!!!
#include <iostream>
using namespace std;
void display(int x[], int n);
void main() {
int arr[100],num;
int i=0, cnt;
cout << "enter the digits of your first integer (one at a time)"
<<endl;
while(1) {
cin >> num;
if (num !=-1) {
arr=num;
i++;
}
else {
break;
}
}
cnt=i;
int arr1[100],num2;
int j=0, cnt1;
cout << "enter the digits of your second integer (one at a
time)"<<endl;
while(1) {
cin >> num2;
if (num2 !=-1) {
arr1[j]=num2;
j++;
}
else {
break;
}
}
cnt1=j;
//display the results
cout << "you entered the numbers: "<<endl;
display(arr, cnt);
cout<<"and"<<endl;
display(arr1, cnt1);
}
void display(int x[], int n) {
int i;
for (i=0; i<n; i++) {
cout << x;
}
cout << "\n";
}