traav!
traav!
I'm flattered....Originally posted by pode
traav!
well that compiles fun if i add that one line, but it still not understand std:cout or std:cingetline but im getting other errors too which isnt suprising since I don't know what any of the tutorial code means or what its doing or how im supposed to use it
What compiler you have? Post the code that isn't working.Originally posted by Noobie
well that compiles fun if i add that one line, but it still not understand std:cout or std:cingetline but im getting other errors too which isnt suprising since I don't know what any of the tutorial code means or what its doing or how im supposed to use it
here is my code, sorry but I dont know how to format it so it looks like it does in notepad - i now have isdigit but it still has the same crash error if i enter a letter
Code:#include <iostream> #include <stdlib.h> #include <time.h> #include <ctype.h> #include <limits> using namespace std; int commandmain(); void funcroll6(void) { int roll6=0, num6roll=0, temproll; cout<<"\n\nEnter a number of 6-sided dice to roll:"; cin>>num6roll; if(isdigit(num6roll)) { cout<<"Be sure to enter a number of dice..."; } else while (num6roll>0) { temproll=(rand() % 6+1); roll6=temproll+roll6; num6roll = num6roll - 1; } cout<<"\n\nYou rolled for a total of "<<(roll6)<<"!"; } int main() { time_t seconds; time(&seconds); srand((unsigned int) seconds); while (commandmain()==0) commandmain(); return 0; } int commandmain() { char command[256]; int commain=0; cout << "\n\nEnter a command:"; cin.getline(command, 256, '\n'); if(!strcmpi("dice", command)) { funcroll6(); } else if(!strcmpi("roll dice", command)) { funcroll6(); } else if(!strcmpi("roll them bones", command)) { funcroll6(); } else if(!strcmpi("help", command)) { cout<<"\nSince this is a dice program, try:\n1.roll dice\n2.dice\n3.r"; cout<<"oll them bones\n4.quit"; } else if(!strcmpi("quit", command)) { commain=-1; } else { cout<<"\nEnter help for assistance:"; commain=0; } return (commain); }
It compiles without a glitch on my compiler, Wich one do you have?Originally posted by Noobie
here is my code, sorry but I dont know how to format it so it looks like it does in notepad - i now have isdigit but it still has the same crash error if i enter a letter
Code:#include <iostream> #include <stdlib.h> #include <time.h> #include <ctype.h> #include <limits> using namespace std; int commandmain(); void funcroll6(void) { int roll6=0, num6roll=0, temproll; cout<<"\n\nEnter a number of 6-sided dice to roll:"; cin>>num6roll; if(isdigit(num6roll)) { cout<<"Be sure to enter a number of dice..."; } else while (num6roll>0) { temproll=(rand() % 6+1); roll6=temproll+roll6; num6roll = num6roll - 1; } cout<<"\n\nYou rolled for a total of "<<(roll6)<<"!"; } int main() { time_t seconds; time(&seconds); srand((unsigned int) seconds); while (commandmain()==0) commandmain(); return 0; } int commandmain() { char command[256]; int commain=0; cout << "\n\nEnter a command:"; cin.getline(command, 256, '\n'); if(!strcmpi("dice", command)) { funcroll6(); } else if(!strcmpi("roll dice", command)) { funcroll6(); } else if(!strcmpi("roll them bones", command)) { funcroll6(); } else if(!strcmpi("help", command)) { cout<<"\nSince this is a dice program, try:\n1.roll dice\n2.dice\n3.r"; cout<<"oll them bones\n4.quit"; } else if(!strcmpi("quit", command)) { commain=-1; } else { cout<<"\nEnter help for assistance:"; commain=0; } return (commain); }
It compiles fine, run the program, it doesnt work right. Enter e for a number of dice, it crashes. Also note how if u roll the dice, it says
Enter a command:
Enter help for assistance:
Enter a command:
Last edited by Noobie; 02-03-2003 at 05:10 PM.
Do you understand this code? Or is this a tutorial? Learn this
code well until you know how it works, Because i can't explain
everything step by step here!
Well, I understood it enough to write it but I obviously don't understand it all because its got errors.
It compiles fineCome again?its got errors
basically if something isnt in this code, I probably have no idea what it is
it compiles fine, but it doesnt work right when i run it-as I said
Entering a letter for the number of dice causes it to crash
After rolling dice, it states
Enter help for assistance:
Enter a command:
Enter help for assistance:_
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
Change those to
#include <cstdlib>
#include <ctime>
#include <cctype>
Also, isdigit is not going to work in your situation... you need to go here and READ THROUGH CAREFULLY.
Remove if (isdigit(num6roll)) ...
and add
Code:while ((std::cout << "Enter a number of 6-sided dice to roll: ") && !(std::cin >> num6roll)) { std::cout << "That's not a number; "; std::cin.clear(); std::cin.ignore(std::numeric_limits<int>::max(), '\n'); }
Didn't we already go over this? isdigit first of all only checks to see if a character is a in the ASCII range of '0' to '9' (decimal values 48-57 i think).
This means isdigit(47) and isdigit(1) will return false while isdigit(48) will return true.
Checking to see if input is correct is slightly advanced so its unlikely you'll understand most of what needs to be done at this point. One way is to use chars instead of ints, but then you'll need to figure out how to change them back. Another way is to do something like this:
You are trying to do things without learning the basics first. Start with the basics and then everything else will slowly begin to make sense.Code:bool good=false; while (!good) { cin>>choice; if (cin.fail()) { while (getchar()!='\n') {}; cin.clear(); } else good=true; }
Last edited by PJYelton; 02-03-2003 at 05:25 PM.
std::cout <---My Borland 5.02 compiler is not understanding this. In addition, Im not understanding it.