Ich bin neu in C++ und versuche, ein einfaches Programm zu erstellen, das mit der Benutzereingabe zum Fortfahren eine zufällige links oder rechts generieren wird. Ich hatte das Programm richtig arbeiten, bis ich in das Array hinzugefügt, um zu versuchen und jedes Element zu speichern, da ich sie so bald ausgeben muss und der Benutzer die Schleife beenden möchte. Das Programm scheint gut zu kompilieren, aber zur Laufzeit erhalte ich "Unhandled exception at 0x012B1CA9" Jede Hilfe würde sehr geschätzt werden.Unbehandelte Ausnahme bei 0x012B1CA9
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
int userSelection = 1;
const int MAX = '100';
int randNum(0);
int one (0);
int two (0);
int total(0);
int sel[MAX];
do
{
cout << "Press 1 to pick a side or 0 to quit: ";
cin >> userSelection;
for (int i = 1; i < MAX; i++)
{
srand(time(NULL));
sel[i] = 1 + (rand() % 2);
if (sel[i] == 1)
{
cout << "<<<--- Left" << endl;
one++;
total++;
}
else
{
cout << "Right --->>>" << endl;
two++;
total++;
}
}
} while (userSelection == 1);
cout << "Replaying Selections" << endl;
for (int j = 0; j < MAX; j++)
{
cout << sel[j] << endl;
}
cout << "Printing Statistics" << endl;
double total1 = ((one/total)*100);
double total2 = ((two/total)*100);
cout << "Left: " << one << "-" << "(" << total1 << "%)" << endl;
cout << "Right: " << two << "-" << "(" << total2 << "%)" << endl;
system("pause");
return 0;
};
ich frage mich, warum Ihr Compiler nicht von 'const int MAX beschwerte = '100' ; ' – WhiZTiM
Ich bin mir nicht sicher, ob ich Visual Studio 2015 verwende. Was sollte die Syntax sein? – CA444
'const int MAX = 100;' –