I realize the very basic idea of classes, but not how they work or how they are coded, could anyway point me to an online resource or explain classes to me themselves?
I realize the very basic idea of classes, but not how they work or how they are coded, could anyway point me to an online resource or explain classes to me themselves?
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
> Classes, what are they?
Classes are a means of information transfer from the teachers notebook to the students notebook without passing through the minds of either
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Aha! Thankyou, I just couldn't figure it out. I'm not sure what dave_sinkula is talking about...looks like some very complicated programming languageOriginally Posted by Salem
Edit: I have another question, it has nothing to do with this. But I have this code and when I input something like "123" for the addmore variable it prints "Invalid Input" for however many characters there are in the variable. I am pretty sure the reason is because addmore is a char data type and it checks each character, how would you get around this?
Code:#include <iostream> #include <vector> #include <string> using namespace std; int main() { vector <int> storage; int number; int cont=0; char addmore; cout<<"Enter a phone number to be stored(Example-7854439012): "; cin>>number; cin.ignore(); storage.push_back(number); for(int i=0;i<1;i) { cout<<"Do you wish to add any more numbers?(y/n)"; cin>>addmore; cin.ignore(); if (isalpha(addmore)) { cout<<"Input is a letter\n"; break; } else { cout<<"Invalid input.\n"; } } cin.get(); return 0; }
Last edited by relyt_123; 09-22-2006 at 07:12 PM.
Well, let's see what happens!
When you enter "123", the characters '1', '2' and '3' are stored in a buffer -- a temporary storage thingamajig. When you cin>> into addmore, you only retrieve the first character '1', which is then processed. The loop will repeat (tip: you can use for(;;){} or while(1){} for an infinite loop) and retrieve '2' from the buffer, which is the next character. Again, it is an invalid character. This goes on until all characters are read from the buffer.
Last edited by jafet; 09-22-2006 at 11:49 PM.
Code:#include <stdio.h> void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){ puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9 /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i] ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][ t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}
Since valid input is 'y' or 'n', and (almost) anything the user types is a character, I would forget about isalpha and just check for 'y' or 'n' and leave everything else to the invalid input part. If you want to ignore the rest of the input after invalid input, use cin.ignore(numeric_limits<streamsize>::max(), '\n');. You need to include <limits> (and <ios> to be perfectly correct).