Author Topic: C++ compiler errors  (Read 4514 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++ compiler errors
« on: March 07, 2011, 08:34:15 am »
I am using Microsoft Visual C++ 2010 and when I compile thic code. It then says running for about a minute then goes away. I never see anything from my program run. what am I doing wrong this has never happened to me before while I was using this software.

This is my code for a MAP style test in math
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 addition();
int subtraction();
int multiplication();
int division();

int score=0;

int main()
{
srand(time(NULL));
int randint, wrongs=0;
for(int i; i<20; i++)
{
if(score<3)
{
randint=randomgen(6,0);
if(randint==5)
{
wrongs+=addition();
}
else if(randint==4)
{
wrongs+=subtraction();
}
else if(randint==3)
{
wrongs+=multiplication();
}
else if(randint==2)
{
wrongs+=division();
}
/* else if(randint==1)
{
wrongs+=simplelinear();
}
else
{
randint=randomgen(3,0);
if(randint==0)
{
wrongs+=determinant();
}
else if(randint==1)
{
wrongs+=scalarmultiplication();
}
else
{
wrongs+=cts();
}
}*/
}
}
system("PAUSE");
}
//Function Definitions
int randomgen(int range, int bottom)
{
int iSecret;
iSecret = rand()%range+bottom;
return iSecret;
}

int addition()
{
int numone, numtwo, answer;
numone=randomgen(900, 100);
numtwo=randomgen(600, 50);
cout << "What is %d + %d equal ", numone, numtwo;
cin >> answer;
cout << "\n";
if(answer==numone+numtwo)
{
score++;
return 0;
}
else
{
return 1;
}
}

int subtraction()
{
int numone, numtwo, answer;
numone=randomgen(200, 799);
numtwo=randomgen(800, 1);
cout << "What is %d - %d equal ", numone, numtwo;
cin >> answer;
cout << "\n";
if(answer==numone-numtwo)
{
score++;
return 0;
}
else
{
return 1;
}
}

int multiplication()
{
int numone, numtwo, answer;
numone=randomgen(900, 100);
numtwo=randomgen(750, 50);
cout << "What is %d * %d equal ", numone, numtwo;
cin >> answer;
cout << "\n";
if(answer==numone+numtwo)
{
score+=2;
return 0;
}
else
{
return 1;
}
}

int division()
{
int numone, numtwo, answer;
numtwo=randomgen(350, 50);
numone=numtwo*randomgen(900, 100);
cout << "What is %d / %d equal ", numone, numtwo;
cin >> answer;
cout << "\n";
if(answer==numone/numtwo)
{
score+=2;
return 0;
}
else
{
return 1;
}
}

It also shows these errors when the code is running
Code: [Select]
'MAP.exe': Loaded 'E:\MAP\MAP\Debug\MAP.exe', Symbols loaded.
'MAP.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll', Cannot find or open the PDB file
The program '[8712] MAP.exe: Native' has exited with code -1073741790 (0xc0000022).
« Last Edit: March 07, 2011, 08:36:21 am 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 Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Re: C++ compiler errors
« Reply #1 on: March 07, 2011, 10:00:45 am »
it doesn't pause after it finishes.

Source: 30 min of learning C last night :/
School: East Central High School
 
Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Lent out, and never returned
____________________________________________________________

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: C++ compiler errors
« Reply #2 on: March 07, 2011, 01:30:33 pm »
system("Pause") is supposed to pause the system

and I found out it was just my AntiVirus(Norton) blocking it.

The %d is not working to add in the variable names how do I do that another way?
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

Ashbad

  • Guest
Re: C++ compiler errors
« Reply #3 on: March 07, 2011, 01:33:26 pm »
hmm, the %d should be working.  I would suggest using something like printf() (or C++'s equivalent, forgot the library it's in) to do that.  I'm not sure if cout accepts it in that format.

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: C++ compiler errors
« Reply #4 on: March 07, 2011, 01:36:01 pm »
right now I am using this as a work around
cout << "What is" << numone << "+" numtwo << "equal"
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

Ashbad

  • Guest
Re: C++ compiler errors
« Reply #5 on: March 07, 2011, 01:37:00 pm »
that should work just fine, though I still advise a formatted print function that does the work for you, it saves space, time, and just easier to use and less stupid mistakes will be made.

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: C++ compiler errors
« Reply #6 on: March 07, 2011, 01:37:44 pm »
I'm not sure how to I just taught myself most of this a little while ago. Any help would be appreciated

EDIT: Here is my newer code
Code: [Select]
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

int randomgen(int range, int bottom);
int addition();
int subtraction();
int multiplication();
int division();

int score=0, wrongs=0;

int main()
{
srand(time(NULL));
int randint;
for(int i=0; i<20; i++)
{
if(score<3)
{
randint=randomgen(6,0);
if(randint==5)
{
wrongs+=addition();
}
else if(randint==4)
{
wrongs+=subtraction();
}
else if(randint==3)
{
wrongs+=multiplication();
}
else if(randint==2)
{
wrongs+=division();
}
/* else if(randint==1)
{
wrongs+=simplelinear();
}
else
{
randint=randomgen(3,0);
if(randint==0)
{
wrongs+=determinant();
}
else if(randint==1)
{
wrongs+=scalarmultiplication();
}
else
{
wrongs+=cts();
}
}*/
if(wrongs>=10)
{
                break;
            }
}
}
system("PAUSE");
}
//Function Definitions
int randomgen(int range, int bottom)
{
int iSecret;
iSecret = rand()%range+bottom;
return iSecret;
}

int addition()
{
int numone, numtwo, answer;
numone=randomgen(900, 100);
numtwo=randomgen(600, 50);
// cout << "What is %d + %d equal ", numone, numtwo; uncomment when figure out how to make it work
cout << "What is " << numone << "+" << numtwo << " equal ";
cin >> answer;
cout << "\n";
if(answer==numone+numtwo)
{
score++;
}
else
{
wrongs++;
}
}

int subtraction()
{
int numone, numtwo, answer;
numone=randomgen(200, 799);
numtwo=randomgen(800, 1);
cout << "What is " << numone << "-" << numtwo << " equal ";
cin >> answer;
cout << "\n";
if(answer==numone-numtwo)
{
score++;
}
else
{
        wrongs++;
    }
}

int multiplication()
{
int numone, numtwo, answer;
numone=randomgen(900, 100);
numtwo=randomgen(750, 50);
cout << "What is " << numone << "*" << numtwo << " equal ";
cin >> answer;
cout << "\n";
if(answer==numone+numtwo)
{
score+=2;
}
else
{
wrongs++;
}
}

int division()
{
int numone, numtwo, answer;
numtwo=randomgen(350, 50);
numone=numtwo*randomgen(900, 100);
cout << "What is " << numone << "/" << numtwo << " equal ";
cin >> answer;
cout << "\n";
if(answer==numone/numtwo)
{
score+=2;
}
else
{
wrongs++;
}
}
« Last Edit: March 07, 2011, 01:52:39 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

Ashbad

  • Guest
Re: C++ compiler errors
« Reply #7 on: March 07, 2011, 01:47:20 pm »
apparently kerm says that sprintf() is part of C++ (I wouold look up the library though) and that's quite useful.  I suggest using that instead.

Offline ruler501

  • Meep
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2475
  • Rating: +66/-9
  • Crazy Programmer
    • View Profile
Re: C++ compiler errors
« Reply #8 on: March 07, 2011, 06:09:06 pm »
I will repost my code in a second. I redid it with printf instead of the couts
sprintf doesn't exist according to Dev-C++

Too many semicolons... I like python

Here is my code
Code: [Select]
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

int randomgen(int range, int bottom);
int addition();
int subtraction();
int multiplication();
int division();
int simplelinear();

int score=0, wrongs=0;

int main()
{
srand(time(NULL));
int randint;
for(int i=0; i<20; i++)
{
        cout << score;
        cout << "\n";
        cout << i;
        cout << "\n";
if(score<3)
{
randint=randomgen(6,0);
if(randint==5)
{
wrongs+=addition();
}
else if(randint==4)
{
wrongs+=subtraction();
}
else if(randint==3)
{
wrongs+=multiplication();
}
else if(randint==2)
{
wrongs+=division();
}
else if(randint==1)
{
wrongs+=simplelinear();
}
/* else
{
randint=randomgen(3,0);
if(randint==0)
{
wrongs+=determinant();
}
else if(randint==1)
{
wrongs+=scalarmultiplication();
}
else
{
wrongs+=cts();
}
}*/
if(wrongs>=10)
{
                break;
            }
}
}
system("PAUSE");
}
//Function Definitions
int randomgen(int range, int bottom)
{
int iSecret;
iSecret = rand()%range+bottom;
return iSecret;
}

int addition()
{
int numone, numtwo, answer;
numone=randomgen(900, 100);
numtwo=randomgen(600, 50);
printf("what is %d+%d ", numone, numtwo);
cin >> answer;
cout << "\n";
if(answer==numone+numtwo)
{
score++;
return 0;
}
else
{
wrongs++;
return 0;
}
}

int subtraction()
{
int numone, numtwo, answer;
numone=randomgen(200, 799);
numtwo=randomgen(800, 1);
printf("what is %d-%d ", numone, numtwo);
cin >> answer;
cout << "\n";
if(answer==numone-numtwo)
{
score++;
return 0;
}
else
{
        wrongs++;
        return 0;
    }
}

int multiplication()
{
int numone, numtwo, answer;
numone=randomgen(900, 100);
numtwo=randomgen(750, 50);
printf("what is %d*%d ", numone, numtwo);
cin >> answer;
cout << "\n";
if(answer==numone+numtwo)
{
score+=2;
return 0;
}
else
{
wrongs++;
return 0;
}
}

int division()
{
int numone, numtwo, answer;
numtwo=randomgen(350, 50);
numone=numtwo*randomgen(900, 100);
printf("what is %d/%d ", numone, numtwo);
cin >> answer;
cout << "\n";
if(answer==numone/numtwo)
{
score+=2;
return 0;
}
else
{
wrongs++;
return 0;
}
}

int simplelinear()
{
int numone, slope, intercept, answer, correct;
slope=randomgen(50, 1);
intercept=randomgen(300, 500);
correct=randomgen(200, 1);
numone=slope*correct-intercept;
printf("what is x if %dx+%d=%d ", slope, intercept, numone);
cin >> answer;
cout << "\n";
if(answer==correct)
{
score+=2;
return 0;
}
else
{
wrongs++;
return 0;
}
}

I have a slight problem with simplelinear. It is not getting the correct answer. Could someone please tell me what I did wrong

EDIT: Norton only blocks in when I compile it in Microsoft visual C++. Dev C++ seems to not cause "viruses".
« Last Edit: March 07, 2011, 06:14:54 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