|
-
August 15th, 2011, 11:36 PM
#1
Assertion Error: Invalid Null Pointer
Hello everyone, I am learning c++ migrating from Visual basic. I have created a sample program in which a random number is generated and a user must guess what the number is. Unfortunately I am being bogged down by an assertion error, and I cannot figure out what is wrong with my code. Here is my code, and the error occurs at line 33. Any help would be much appreciated!
Code:
#include "stdlib.h"
#include "stdio.h"
#include "string.h"
#include <sstream>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
char thing = NULL;
vector<int> randNum(4);
vector<int> guesses(4);
cout << "Enter any number \n";
int awesome;
cin >> awesome;
srand(awesome);
cout << "Guess the four correct digits \n";
int bulls = 1;
int cows = 1;
string input = 0;
while (bulls < guesses.size()) {
bulls = 0;
cows = 0;
cout << "Enter Four Digits";
cin >> input;
for(int i = 0; i< randNum.size(); i++) {
randNum[i] = rand() % 10;
guesses[i] = atoi(input.substr(0, 1).c_str());
//5 = 4359
}
for (int ii = 0; ii < randNum.size(); ii++) {
for(int j = 0; j < guesses.size(); j++) {
if(guesses[j] == randNum[ii] && j == ii){
bulls += 1;
}
else if(guesses[j] == randNum[ii]){
cows += 1;
}
} //end for (int j)
} //end for(int ii)
if (bulls < guesses.size()) {
cout << " You have guessed" << bulls << " bulls and " << cows << " cows";
}
else
{
"Congratulations! The number you have guessed is correct!";
} //end if(bulls < 4)
} // end while bulls < 4
cin >> thing;
//keeps the console window open
return 0;
}
Last edited by cilu; August 16th, 2011 at 12:34 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|