C++ Programming GalleryThe Programming Challenge

Challenge 6 – Why does multiplication not return the correct value? in C++

Difficulty x10
x5

This Challenge was proposed for the now defunct C/C++ programming list CWORLD in 1999.
The source code of the challenge has been updated to modern C++, but maintaining the essence of the challenge, which its original author wanted to transmit.

Date: 11-IX-2000
Created by: Aurelio Márquez
Challenge winner: José Luis De la Cruz

Can you find the error?. It’s very easy.

To solve it you have to make some small changes.

Source Code

#include <iostream>

int main()
{
	int num1, num2;
	long long result;
	num1 = 500000;
	num2 = 300000;
	result = num1 * num2;
	std::cout << "Result = " << result;
	
	return 0;
}

AND FINALLY I CAN ONLY SAY …. BEST OF LUCK AND MAY THE BEST CODE WIN….

If you liked this challenge remember to leave a comment in our guestbook

Solution

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button