SRL Archive - C/C++ Help and Tutorials

Having some c++ issues


All that is man

2009-10-24 00:05:32

Alright well I've been trying to learn c++ for the past couple days… And this is what I've come up with. Please bear with me, that this is coming from a noob :)

#include<iostream>
#include"FunRc.rc"
using namespace std;

int main( void ){
string name;
string age;
bool correct;

name = prompt( "What is your name?", false, 0);
age = prompt( "Great, and how old are you?", true, 1 );
correct = yesorno( "So your name is " + name + " and your " + age + " years old?" );
if( correct ){
cout << "Great! Standby..." << endl;
}
if( correct = false ){
cout << "Well please reenter the information...";
endls( 2 );
}
system( "PAUSE" );
}

And this is FunRc.rc:


using namespace std;

void endls( int amount ){
int tempInt;

tempInt = 0;
while( tempInt != amount ){
cout << "" << endl;
tempInt = tempInt + 1;
}

}

string prompt( string question, bool endlinebefore, int endlines ){
string result;

if( endlinebefore ){
endls( 1 );
}
cout << question << endl;
cin >> result;
endls( endlines );
return result;
}

bool yesorno( string question ){
char temp;

cout << question << " <y / n>" << endl;
cin >> temp;
if( temp = 'y' ){
cout << "true" << endl;
return true;
}
if( temp = 'n' ){
cout << "false" << endl;
return false;
}
}

But no matter what I get this:


Its probally something really nooby but give me a break :)

bullzeye95

2009-10-24 00:16:14

Change:
     if( temp = 'y' ){
cout << "true" << endl;
return true;
}
if( temp = 'n' ){
cout << "false" << endl;
return false;
}
To:
     if( temp == 'y' ){
cout << "true" << endl;
return true;
}
if( temp == 'n' ){
cout << "false" << endl;
return false;
}
= sets a value, and == compares two values. You'll also need to change
 if( correct = false ){
to
 if( correct == false ){

All that is man

2009-10-24 00:24:03

Ahhh!!! So = in c++ is like := in scar and == in c++ is like = scar?