All sorts of errors

My program was compiling fine until just recently, when a bunch of errors appeared. I cannot figure out why they exist.



The errors are as follows:
(30): warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
(9): warning C4101: 'time' : unreferenced local variable
(35): error C2059: syntax error : 'else'
(35): error C2447: '{' : missing function header (old-style formal list?)
(53): error C2059: syntax error : 'return'
(54): error C2059: syntax error : '}'
(54): error C2143: syntax error : missing ';' before '}'
Last edited on
I compiled and ran the program as-is with no errors?
Maybe its a problem with Visual Studio then?
are you entering random data to test it? Let me try with the data you give me as input.
I've been entering 10000, 100, 100 or 10000, 75, 100. I reloaded VS and it worked again, so I guess that was the problem.
You probably forgot to compile then tried to run and those were the previous errors.
fuel_required = (1 - altitude / 200000.0) * beam_strength;

This will cause the conversion error. fuel_required is of type int, but the calculation result is double. If you really want the loss of precision, you can cast the answer to an int to prevent the warning, by using static_cast<int>

However, you are probably better off making all the variables double as you can avoid the integer division trap without having to remember each time.

Also, some compilers don't have the conversion warning on by default. For example gcc, with -Wall -Wextra -pedantic on, still doesn't show this warning - it must be turned on manually with -Wconversion. Which means that you must have an explicit cast to prevent the warning.

There are others too, that for some might be handy: -Woverloaded-virtual -Wmissing-include-dirs -Wswitch-default -Wuninitialized -Wfloat-equal.

Last edited on
1. The messages are from compiler, not runtime.
2. Warnings are not errors.
3. First real error is "(35): error C2059: syntax error : 'else'". It probably causes the second warning and rest of errors too. The shown code does not explain that error.
I compiled every time. I just shut down VS and opened it back up and it worked, no warnings or errors. No code change or anything, and its been working fine since.
I compiled every time. I just shut down VS and opened it back up and it worked, no warnings or errors.


And which warning option do you have set? Just trying to get you into a good practice, the code you had earlier (now deleted) should produce a warning.
Topic archived. No new replies allowed.