Getting a decimal place by dividing integer.

I'm trying to do a arithmetic calculator when the user input 2 4-digit integer.
However, whenever i'm trying to get the division with reminder I'm not able to do so.

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
  int main()

{

	int firstNo, secondNo;

	cout << "Enter two no-zero 4-digits integers:" << endl;
	
	cout << endl;	 
	
	cin >> firstNo >> secondNo;
	
	cout << endl;
	
	//obtain last value
	
	int firstDigit = firstNo % 10;
	int secondDigit = secondNo % 10;
	
	 
	int addfirstNumbers = firstDigit + secondDigit;
	int minusfirstNumbers = firstDigit - secondDigit;
	int multiplefirstNumbers = firstDigit * secondDigit;
	int modfirstNumbers = firstDigit % secondDigit;
	double divfirstNumbers = firstDigit / secondDigit;

     cout <<"divfirstNumbers"; //gives me an integer

	
}


P.S : I'm purposely this calculator in long way. I do know that it is possible to do this calculator the shorter way via a for loop or a while function.

But the main thing here is i'm trying to get the value from the division with the reminder but however, I'm only getting the integer as I'm dividing the value based on integer.
Last edited on
To get the remainder use the % operator.

1
2
13 / 5 = 2;
13 % 5 = 3;
Hi,
cout <<"divfirstNumbers"; //gives me an integer

You seem to be having trouble trying to output something other than a literal string. This :
cout <<"divfirstNumbers: " << divfirstNumbers << endl;

Funny though :)
Topic archived. No new replies allowed.