[Question]
  [
**Closed.** This question is [off-topic](/help/closed-questions). It is not currently accepting answers.
 
 
---
 Questions without an **objective primary winning criterion** are off-topic, as they make it impossible to indisputably decide which entry should win.
Closed 8 years ago.
[Improve this question](/posts/8506/edit) 
This is the first of a series of C++ puzzles for you. Hope you will enjoy.
So, puzzle no.1:
Given the following program:
```
#include <iostream>
int main() 
{
   const int a=1;
   const int b=2;
   const float c=0.5;
   std::cout << a/b-a*c;
}
```
Insert some code on a single new line anywhere inside the program so that the output will be 0. The new line will contain AT MOST 18 characters (including spaces), and the rest of the lines will remain unmodified.
 To be clear, here is an example of a valid new code:
```
#include <iostream>
int main() 
{
   const int a=1;
   const int b=2;
   int* p = NULL;
   const float c=0.5;
   std::cout << a/b-a*c;
}
```
A new line with 15 characters was inserted so it's ok. However it does not solve the problem.
If this is too simple for you, don't worry, more is coming!!
  
[Answer]
We can get rid of a=1 by moving it into another scope:
```
#include <iostream>
main() 
{
int a=0;if(0)
    const int a=1;
    const int b=2;
    const float c=0.5;
    std::cout << a/b-a*c;
}
```
This is I think 13 characters. Or better yet get a new `a` that also results in 0:
```
#include <iostream>
int main() 
{
   const int a=1;
   const int b=2;
   const float c=0.5;
if(int a=2)
   std::cout << a/b-a*c;
}
```
That's 11 characters
[Answer]
```
#include <iostream>
main() 
{
   const int a=1;
#define a 0
   const int b=2;
   const float c=0.5;
   std::cout << a/b-a*c;
}
```
1 new line, 12 new chars
[Answer]
So, `#define a 0`, Done. I saw that was posted - unsurprisingly.
Surprisingly, this wasn't posted:
```
#include <iostream>
main() 
{
   const int a=1;
   const int b=2;
   const float c=0.5;
   std::cout<<0||
   std::cout << a/b-a*c;
}
```
*14 chars*
That should do, right?
[Answer]
```
#include <iostream>
main() 
{
const int a=0;//\
   const int a=1;
   const int b=2;
   const float c=0.5;
   std::cout << a/b-a*c;
}
```
17 chars.
By the way, the original program doesn't compile under MSVC, which complains that `main` doesn't have a return type.
[Answer]
```
#define int float
```
should work as well and is the same length.
[Answer]
18, including newline
```
#define float int
```
[Answer]
```
#include <iostream>
int main() 
{
   const int a=1;
   const int b=2;
   const float c=0.5;
   1?std::cout<<0:
   std::cout << a/b-a*c;
}
```
15 chars.
[Answer]
```
#include <iostream>
main() 
{
   const int a=1;
   const int b=2;
   const float c=0.5;
#define a 0;1
   std::cout << a/b-a*c;
}
```
14 characters.
[Answer]
```
#include <iostream>
main() 
{
   const int a=1;
   const int b=2;
   const float c=0.5;
   return puts("0");
   std::cout << a/b-a*c;
}
```
17 chars. 
[Answer]
```
#include <iostream>
main()
{
   const int a=1;
   const int b=2;
   const float c=0.5;
std::cout<<0;//\
   std::cout << a/b-a*c;
}
```
It's 17 characters so it just fits.
[Answer]
I do not know C++, however based on the question, couldn't you just input a line to simply output 0? the question specifies the output should be 0, it does not specify you must CHANGE the output to 0.
```
std::cout << 0
```
(I have 0 clue on C++, perhaps somebody can use this concept though)
[Answer]
12 chars, similar to mob's solution
```
#include <iostream>
int main() 
{
   const int a=1;
   const int b=2;
   const float c=0.5;
#define a b
   std::cout << a/b-a*c;
}
```
other combinations also work, like `#define a c` or `#define c 0`
[Answer]
I know it's not [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), but I seem to be wearing that hat today!
```
#include <iostream>
int main() 
{
   const int a=1;
   const int b=2;
   const float c=0.5;
```
# --a;
```
   std::cout << a/b-a*c;
}
```
five chars, including the newline;
[Answer]
c++ whatever...
```
echo "0"; exit
#include <iostream>
int main() 
{
   const int a=1;
   const int b=2;
   const float c=0.5;
   std::cout << a/b-a*c;
}
```
run via:
```
sh mp.cpp
```
[Answer]
A variant on [Mr Lister's answer](/a/8513) but slightly less obvious.
```
#include <iostream>
int main() 
{
   const float a=1; //??/
   const int a=1;
   const int b=2;
   const float c=0.5;
   std::cout << a/b-a*c;
}
```
[Answer]
```
#include <iostream>
int main() 
{
int a;if(a)
   const int a=1;
   const int b=2;
   const float c=0.5;
   std::cout << a/b-a*c;
}
```
How about these 11 chars...
[Answer]
```
#define a 0
```
<http://codepad.org/N06weGJc>
```
#include <iostream>
int main() 
{
   const int a=1;
   const int b=2;
   const float c=0.5;
#define a 0
   std::cout << a/b-a*c;
}
```
]