Dan Posted April 18, 2005 Report Share Posted April 18, 2005 I was up making a mini proggie to test out what I learned, and I had this (After the beginning stuff):char answer1;cout <<"Is 4 (<,>,=) to 7?";cin >> answer1Can someone enter a symbol as a char? Quote Link to post Share on other sites
Matt Posted April 18, 2005 Report Share Posted April 18, 2005 we talked on AIM.. like I said, I don't think those can be stored in a char, and I don't think the computer would be able to recognize their meanings in relation to the cout text. Try putting each option represented by an int (eg 1. < 2. > etc...) and work from there.Matt Quote Link to post Share on other sites
iccaros Posted April 18, 2005 Report Share Posted April 18, 2005 (edited) it works as long as you case it correctly..the nice part is you can chnage this so questions and value coem from a file....#include <iostream>using namespace std;int main (){ char Test; int a = 12; int b = 7; cout << "Answer is 12 > or < 7 (enter > or <): "; cin >> Test; switch ( Test ) { case '>': if ( a > b ){ cout << "correct answer" << endl;} else cout << "wrong answer looser" << endl; break; case '<': if (a < b ){ cout << "correct answer" << endl;} else cout << "wrong answer looser" << endl; break; } return 0;} Edited April 18, 2005 by iccaros Quote Link to post Share on other sites
Matt Posted April 19, 2005 Report Share Posted April 19, 2005 wow - I didn't know about case. Thanks iccaros, Ill look into that.Matt Quote Link to post Share on other sites
jcl Posted April 19, 2005 Report Share Posted April 19, 2005 (edited) For future reference, the basic source character set, the character set available for use in source code, consists of the following characters:ABDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuzwxyz0123456789!"#%&'()*+,-./:;<=>?[\]^_{|}~and space, and control characters for horizontal (\t) and vertical (\v) tabs, form feed (\f), and newline (\n).The basic execution character set, the character set that can be used at runtime e.g. for input, consists of all the source characters plus control characters for alert (\a), backspace (\, carriage return (\r), and the null character (value 0).Some implementations may support other characters, for example most support the entire ASCII character set and a great many support 8-bit character sets (e.g. various ISO 8859).There's also wide-character sets (used with the type wchar_t) that are potentially (much) larger. Edited April 19, 2005 by jcl Quote Link to post Share on other sites
Dan Posted April 19, 2005 Author Report Share Posted April 19, 2005 Cool! Thanks. Like Matt said, I will look into that too.I was just making a proggie for Ch 5 of the book, to demonstrate looping...Now this stupid RHIDE program is telling me the a "break;" is not inside a loop -- which it is...(or I think it is...).// a simple program. Used to be as a math "test". Multiple choice (3 for now,// can be changed.... Also for what I learned in CH. 5#include <cstdio>#include <cstdlib>#include <iostream.h>int main (){cout <<"Welcome to this program. This will ask you a few questions. Answer 1 for <, 2 for >, and 3 for =.\n";cout <<"Question 1: \n";int answer1;cout <<"4 is <, >, = to 7??";cin >> answer1;//If answer rightif (answer1 == 1){ cout <<"\nThat answer is correct.";}{cout <<"\nWrong. The correct answer is >.";}int answer2;cout <<"\n5.0211 is <, >, = to 5.2011?"; cin >> answer2;if (answer2 == 2){cout <<"\nCorrect.";}{cout <<"\nWrong. The correct answer is <.";}int answer3;cout <<"\n5 over 8 is <, >, = to .635?";cin >> answer3;if (answer3 == 2){cout <<"Correct";}{cout <<"Incorrect. The correct answer is <.";}int exit;cout <<"\nDo you want to quit? (0 for quit, 1 to start over)";cin >> "exit";if (exit == 0){break; //this is the break; where the compiler is giving me errors}{system("PAUSE");return 0;}} Quote Link to post Share on other sites
iccaros Posted April 19, 2005 Report Share Posted April 19, 2005 if (exit == 0){break; //this is the break; where the compiler is giving me errors}else{system("PAUSE");}return 0; Quote Link to post Share on other sites
jcl Posted April 19, 2005 Report Share Posted April 19, 2005 (edited) I was just making a proggie for Ch 5 of the book, to demonstrate looping...Now this stupid RHIDE program is telling me the a "break;" is not inside a loop -- which it is...(or I think it is...).There aren't any loops in that code.Also, you should be using iostream instead of iostream.h. The latter is pre-ISO C++. And using 'exit' as a variable name when the exit() function is in scope is asking for trouble. Edited April 19, 2005 by jcl Quote Link to post Share on other sites
Dan Posted April 19, 2005 Author Report Share Posted April 19, 2005 Ok, I changed the name, now it's still saying that break isn't in the code...There aren't any loops in that code.Why not...the "if" command was in the "Loop" section of the book...I just put a bracket on the end of the whole thing, now its saying... "Virtual Memory Exausted." Quote Link to post Share on other sites
jcl Posted April 19, 2005 Report Share Posted April 19, 2005 Why not...the "if" command was in the "Loop" section of the book...Conditionals don't create loops in the flow of control: the flow enters the conditional, possibly takes one of the branches, and then exits the conditional and continues on. Why they would be introduced as loops I cannot say.I just put a bracket on the end of the whole thing, now its saying... "Virtual Memory Exausted."Where at the end? Quote Link to post Share on other sites
Dan Posted April 19, 2005 Author Report Share Posted April 19, 2005 Actualy, it was in the same section as the loops! So how do I break from an if statement.And the error has gone away... Quote Link to post Share on other sites
jcl Posted April 19, 2005 Report Share Posted April 19, 2005 So how do I break from an if statement. You don't. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.