PDA

View Full Version : Having some c++ issues



All that is man
10-24-2009, 04:05 AM
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:
http://img194.imageshack.us/img194/2183/cerror.th.jpg (http://img194.imageshack.us/i/cerror.jpg/)

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

bullzeye95
10-24-2009, 04:16 AM
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
10-24-2009, 04:24 AM
Ahhh!!! So = in c++ is like := in scar and == in c++ is like = scar?