Author Topic: C++ strange errors  (Read 5301 times)

0 Members and 1 Guest are viewing this topic.

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
C++ strange errors
« on: February 21, 2011, 11:01:06 pm »
I have been trying to make a math quiz to assist me in finding out my own skill compared to others and possibly to help me in my math tutorial style book. Here is my code to try and generate 5 random numbers from 1-5. It is displaying strange errors
Code: [Select]
/* rand example: guess the number */
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

int randomgen(int range, int bottom);

int main()
{
for(int i=0; i<5;i++)
{
int num;
num = randomgen(5, 1);
cout << num << endl;
}
system("PAUSE");
}

int randomgen(int range, int bottom)
{
int iSecret;
srand(time(NULL));
iSecret = rand()%range+bottom;
return iSecret;
}

Errors
Code: [Select]
'Chapter1.exe': Loaded 'E:\Book\Software\Chapter1\Release\Chapter1.exe', Symbols loaded.
'Chapter1.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll', Cannot find or open the PDB file
'Chapter1.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll', Cannot find or open the PDB file
'Chapter1.exe': Loaded 'C:\Program Files\Alwil Software\Avast5\snxhk.dll', Cannot find or open the PDB file
'Chapter1.exe': Loaded 'C:\WINDOWS\system32\msvcp100.dll', Symbols loaded.
'Chapter1.exe': Loaded 'C:\WINDOWS\system32\msvcr100.dll', Symbols loaded.
'Chapter1.exe': Loaded 'C:\WINDOWS\system32\shimeng.dll', Cannot find or open the PDB file
'Chapter1.exe': Unloaded 'C:\WINDOWS\system32\shimeng.dll'
The program '[2980] Chapter1.exe: Native' has exited with code 0 (0x0).

I don't know what is going on please help
« Last Edit: February 21, 2011, 11:29:12 pm by ruler501 »
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: C++ strange errors
« Reply #1 on: February 21, 2011, 11:05:14 pm »
What are you compiling this with?

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: C++ strange errors
« Reply #2 on: February 21, 2011, 11:06:13 pm »
Microsoft Visual C++ 2010 Express Edition
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline Binder News

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 785
  • Rating: +46/-3
  • Zombie of Tomorrow
    • View Profile
Re: C++ strange errors
« Reply #3 on: February 21, 2011, 11:18:34 pm »
first, cstdlib and stdlib.h are the same thing. Pick one (I recommend stdlib.h).
Second, you aren't using stdio.h (I don't think), so get rid of that as well.
Third, the iostreams are buffered. This means that they accumulate data in a buffer, then send in all out at once to somewhere (the console in this case). This write is called a flush. To get the data to be flushed to the console, you need to change
Code: [Select]
cout << num;
to
Code: [Select]
cout << num << endl;
or
Code: [Select]
cout << num << flush;
Spoiler For userbars:







Hacker-in-training!   Z80 Assembly Programmer     Axe Programmer
C++ H4X0R             Java Coder                           I <3 Python!

Perdidisti ludum     Cerebrum non habes

"We are humans first, no matter what."
"Fame is a vapor, popularity an accident, and riches take wings. Only one thing endures, and that is character."
Spoiler For Test Results:





Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: C++ strange errors
« Reply #4 on: February 21, 2011, 11:23:49 pm »
I updated the code in the first post and  it is still giving me the same errors
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline Binder News

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 785
  • Rating: +46/-3
  • Zombie of Tomorrow
    • View Profile
Re: C++ strange errors
« Reply #5 on: February 21, 2011, 11:24:46 pm »
Is it producing the output?
Spoiler For userbars:







Hacker-in-training!   Z80 Assembly Programmer     Axe Programmer
C++ H4X0R             Java Coder                           I <3 Python!

Perdidisti ludum     Cerebrum non habes

"We are humans first, no matter what."
"Fame is a vapor, popularity an accident, and riches take wings. Only one thing endures, and that is character."
Spoiler For Test Results:





Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: C++ strange errors
« Reply #6 on: February 21, 2011, 11:28:23 pm »
I have it working now I added one line of code It shows the output but those errors still pop up

EDIT: I just found a problem it only shows one number as output all 5 times
« Last Edit: February 21, 2011, 11:31:23 pm by ruler501 »
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline Binder News

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 785
  • Rating: +46/-3
  • Zombie of Tomorrow
    • View Profile
Re: C++ strange errors
« Reply #7 on: February 21, 2011, 11:42:10 pm »
The errors are actually not errors. It is the VC++ debugger saying it has or hasn't loaded a PDB file for the specific assembly library. (I won't go into more detail, just know it doesn't matter)
The same-number bug is because you set the random seed on every call.
You should set the seed up front (before the for loop), then not mess with it afterwards. Otherwise, it is resetting the seed each time.
Spoiler For userbars:







Hacker-in-training!   Z80 Assembly Programmer     Axe Programmer
C++ H4X0R             Java Coder                           I <3 Python!

Perdidisti ludum     Cerebrum non habes

"We are humans first, no matter what."
"Fame is a vapor, popularity an accident, and riches take wings. Only one thing endures, and that is character."
Spoiler For Test Results:





Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: C++ strange errors
« Reply #8 on: February 21, 2011, 11:44:29 pm »
thank you it seems to be working now. I'll post here if any strange things start happening.
I currently don't do much, but I am a developer for a game you should totally try out called AssaultCube Reloaded download here https://assaultcuber.codeplex.com/
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

Offline Binder News

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 785
  • Rating: +46/-3
  • Zombie of Tomorrow
    • View Profile
Re: C++ strange errors
« Reply #9 on: February 21, 2011, 11:46:44 pm »
You're very welcome! :)
Spoiler For userbars:







Hacker-in-training!   Z80 Assembly Programmer     Axe Programmer
C++ H4X0R             Java Coder                           I <3 Python!

Perdidisti ludum     Cerebrum non habes

"We are humans first, no matter what."
"Fame is a vapor, popularity an accident, and riches take wings. Only one thing endures, and that is character."
Spoiler For Test Results: