Code::Blocks Forums
User forums => Help => Topic started by: LDgaming on February 25, 2014, 04:10:11 am
-
I keep having an issue with my variables.
For example I have the following code (see below). But the output isn't correct. The output was correct a week ago when I finished it but now its out putting things like 1 * 2 is 747808. This problem is spilling over to all of my other programs.
How can I fix this?
#include <iostream>
using namespace std;
int main()
{
int i = 0;
int j = 0;
int array[8][8];
for ( int i = 0; i < 8; i++ )
{
for ( int j = 0; i < 8; i++)
{
array[j] = i * j;
}
}
cout << "multiplication table:\n";
for ( int i = 0; i < 8; i++ )
{
for ( int j = 0; j < 8; j++ )
{
cout << " [ " << i <<" ][ " << j << " ] = ";
cout << array[ i ][ j ] << " ";
cout << "\n";
}
}
}
-
This is a programming problem; therefore NOT valid on this site.
Please read the CB Rules and FAQs.
http://forums.codeblocks.org/index.php/topic,9996.0.html (http://forums.codeblocks.org/index.php/topic,9996.0.html)
http://wiki.codeblocks.org/index.php?title=FAQ (http://wiki.codeblocks.org/index.php?title=FAQ)
If you think it is a Compiler problem please read on follow this link http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F (http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28general%29#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F)
I suggest turning up the Compiler Warnings.
If you tell us the compiler we might be able to tell you how to turn up the warnings.
Tim S.
-
I think you miss understand me. My programs work. I had proper outputs, but today when I tried to run any of my programs none of the outputs were properly working. Regardless of which program I tried to use. I can't even compile the hello world program.
How is this a programming problem if the program worked before but now I'm getting garbage out?
-
First:
always use code-tags (the little # in the forums-editor), if you post code.
Second it's definitely a programming issue, at least if you used copy and paste for your code.
By the way, it does not even compile here, but even if this is fixed, there is a simple error in one of your loops.
I think you find it yourself if you double-check them again.
Third: as Tim states that post violates our forum rules (http://forums.codeblocks.org/index.php/topic,9996.0.html).
Please (re-)read them.
When registering here, you accepted to follow these rules, so please do so.
Thank you!