EOD#3

Posts 18 of 8 · Page 1 of 1
EOD#3
E.O.D.
Error of the Day

Answer to EOD#2: The trick to this one was that the cout was printing the numbers in octal. A lot of people got this right. Goodjob.


Now I know a lot of you are wondering why these aren't coming out everyday. Well the main reason is that I'm still finishing up learning the basics as I put these up. The real reason I was going to start to do this is to give me refreshers while I try to learn the Windows API and get started reversing. So until I completely learn C++ this isn't as much of priority for me because I'm learning stuff everyday. Anyway I had time today so I figured I would post another one . This like most of the other EOD will be quite easy. theres just one main flaw in it. I like what BA is doing with IQOD so please type answers in white, but you can still discuss in black this is meant to be a discussion not a quiz.


E.O.D. #3
The problem is this program is supposed to sum all the numbers from 1 to 100, but it doesn't do it right? Weird seems everything is set up right :L. What's the problem? Again that's for you to figure out.

Code:
#include <iostream>
using namespace std;

int main()
{
    int sum;
    int count;
    
    for(count = 1; count <= 100; ++count) sum += count;
    
    cout << "The sum of the numbers between 1 and 100 is " << sum << endl ;
    system("pause");
    return 0;
}
Goodluck. No hints this time. I doubt you will need them.
Oh your gonna learn the windows api too? It seems interesting Indeed.

The problem is
<!--
Could it be because you did sum+=count, which means sum = sum + count. yet sum wasn't given an initial value yet, so you are adding with a valueless variable, which equals death.
-->
That's would be correct Windows just assigns sum whatever garbage value was in that address.
Quote Originally Posted by why06 View Post
That's would be correct Windows just assigns sum whatever garbage value was in that address.
wait wtf? all values you make(int f) are initialized as 0
Quote Originally Posted by Hell_Demon View Post
wait wtf? all values you make(int f) are initialized as 0
Did you run the source?
int sum; == garbage
Quote Originally Posted by why06 View Post
Did you run the source?
no, but nevermind, tried creating an array of 100 ints without initallizing came out pretty random ;o

int main()
{
int sum=0;
int count;

for(count = 1; count < 100; count++) sum += count;

cout << "The sum of the numbers between 1 and 100 is " << sum << endl ;
system("pause");
return 0;
}

4950 is it not?


still wondering why windows fills it with random crap
Quote Originally Posted by Hell_Demon View Post
no, but nevermind, tried creating an array of 100 ints without initallizing came out pretty random ;o

int main()
{
int sum=0;
int count;

for(count = 1; count < 100; count++) sum += count;

cout << "The sum of the numbers between 1 and 100 is " << sum << endl ;
system("pause");
return 0;
}

4950 is it not?


still wondering why windows fills it with random crap

Guess it just doesn't bother to clear it :l In Java it does this automatically, but then again it uses a runtime
Posts 18 of 8 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

Need help?