Yes im a noob i just wanted to put in a simple code just for an experiment. No errors, but nothing appears:
#include %26lt;iostream%26gt;
using namespace std;
int main (void)
{
bool btrue;
bool bfalse;
char bresult;
cout %26lt;%26lt; "Twenty Percent of All Americans Are African American ";
cout %26lt;%26lt; "please enter true or false ";
cin %26gt;%26gt; btrue;
cin %26gt;%26gt; bfalse;
bresult = btrue; cout %26lt;%26lt; "The Correct Answer is false ";
bresult = bfalse; cout %26lt;%26lt; "You Are Correct ";
system ("pause");}
Why doesnt my source code work for C++?
Your input is a text string your test is boolean so both bresults fail, you must convert the "true" and "false strings to boolean values
Reply:If I were you...
#include %26lt;iostream%26gt;
using namespace std;
int main(){
start:
string answer;
cout%26lt;%26lt;"Twenty percent of Americans are African American, true(t) false(f)?\n";
cin%26gt;%26gt; answer;
getline(cin, answer, '\n');
if(answer == "t" || "T")
{
cout%26lt;%26lt;"The correct answer is false.\n";
}
else if(answer == "f" || "F")
{
cout%26lt;%26lt;"You are correct.\n";
}
else {
cout%26lt;%26lt;"Invalid Input\n";
goto start;
}
I haven't run it through my compiler yet, but I will, email me if you have problems
s3klyma@yahoo.com
Just in case, I use dev-c++, which you can find at
http://www.bloodshed.net/dev/devcpp.html
just click to download from sourceforge..
get the beta release... That is.. if you need a compiler
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment