why no worky?

hi! i just started programming and am taking a class, im wondering if you could help me understand why this if statement crashes the program. i include some lines from top of program since maybe it has something to do with it.

#include <iostream>
#include <cctype>
#include <string>
using namespace std;
char* C_type = new char[100]; // create array to store types
int* KWH_used = new int[100]; // create array to store kwh used


cout << "How many kilowatt hours did this customer use? ";
cin >> KWH_used[x];
if ( isalpha(KWH_used[x]) ) //why no worky?
//if (KWH_used[x] > 5000) (im using this currently to work)
cout << "Sorry that is not valid input.(DELETING CUSTOMER TYPE)" << endl;
else
x++;
Don't use cin >>
http://www.cplusplus.com/forum/articles/6046/

The code snippet you've posted is ok. What ranges do you have X going to?
x starts at 0 and increases up to array size. i forgot to mention that the program crashes when the user enters a letter at cin >> KWH_used[x]

numbers work fine. so maybe its crashing before if statement. ill look at that link to see if it helps.
Last edited on
That link perfectly identifies and solves your problem :)
Topic archived. No new replies allowed.