Extracting Digits

Need some help with extracting digits from inserted integer :(
I have some errors, I am a beginner, please help me out
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  
#include <iostream>
using namespace std;


int main()
{


		int number1, number2;
		
		
		cout << "Enter two integers: ";
		cin >> number1 >> number2;
		
		
		
		extNumber = number1%10;
		extNumber = number2%10;
		
		
		cout << extNumber;
			
			
}
		

You have not declared a variable called "extNumber", but you are trying to assign to it on lines 18 and 19, and perhaps on line 19 you'd want to assign the result of number2%10 to a different variable?
Can I know how can I do that?


int extNumber?

So sorry and thank you
You are correct on the int extNumber. I would strongly advise you to listen to mutexe in relation to assigning the result of number2%10 to a different variable.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

#include <iostream>
using namespace std;


int main()
{


		int number1, number2;
		int extNumber;
		int extNumber1;
		
		
		cout << "Enter two integers: ";
		cin >> number1 >> number2;
		
		
		
		extNumber = number1%4;
		extNumber1 = number2%4;
		
		
		cout << extNumber;
		cout << extNumber1
			
			
}
		


Seems like the modulus part is wrong and I can't get each digit extracted.

Can you guys help me out, this is my assignment :(
closed account (48T7M4Gy)
What is the assignment question? What r u trying to program?
http://i61.tinypic.com/2mhacf7.png

This is the question :( I am stuck
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
using namespace std;

int main()
{


		int n1, n2;
		int d1 = 0, d2 = 0, d3 = 0, d4 = 0;
		int e1 = 0, e2 = 0, e3 = 0, e4 = 0;
		
		cout << "Enter two 4 digit integers: ";
		cin >> n1 >> n2;
		
		d1 = n1 % 10;
		n1 = n1 / 10;
		
		d2 = n1 % 10;
		n1 = n1 / 10;
		
		d3 = n1 % 10;
		n1 = n1 / 10;
		
		d4 = n1 % 10;
		
		
		// First answer
		cout << d1 + e1 << ' ' << d2 + e2 << ' ' <<  d3 + e3 << ' ' << d4 + e4;
}


This is a very simple start to how you can do it.
You need to extend it by first getting the e1 etc values
Last edited on
Oh my god, Kemort thanks so much for the start. I will try out myself now. So grateful otherwise I am pretty much failing my assignment.
closed account (48T7M4Gy)
OK Cya :)

Hint: when you get to division, integer division can give you 0 for an answer, 2/3 = 0 but (float)(2)/3 = .66 etc
Last edited on
Topic archived. No new replies allowed.