Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Help witth this C++ code!! (simple)
Name: mdude Date: December 7, 2008 at 02:39:37 Pacific OS: xp CPU/Ram: 512 Product: Dell / 12
Comment:
Hello im just starting C++ and i dont get why this isnt working. I hope you can see what i want it to do. I want to cout something IF the cin was a specific input. Here's the code.... #include using namespace std; int main() { char Answer[4]; cout<<"please say yes: "; cin>>Answer; cin.ignore(); if (Answer[4] == "yes") { cout<<"You said yes"; } cin.get(); }
Name: dave19 Date: December 7, 2008 at 05:43:04 Pacific
Reply:
I think you will need to compare each element of an array string like Answer[0] == 'y' Answer[1] == 'e' so on.. or you can do this simply by including <string> header file.. int main( ) { string answer("yes"); char ans[4]; cout<<"Enter your answer: "; cin>>ans; string get(ans); if (answer.compare(get) == 0) cout<<"you said yes"<<endl; else {cout<<"you said "<<get<<endl;} } or you can use char Answer; and get the input as 'y' or 'n' and simply compare it using IF.
Summary: this c code have the error at this line "while((fscanf(fin,"%c",&letter)=EOF))" when i complier it and that put up a error msg. If anyone could Debug this code, i am very thank you very much. #include...
Summary: My program will not output the second part : where it has to add the even numbers and show the sum. I did not code the third part with letters yet... Please help with this... //***********************...
Summary: Hey. Would anyone please help me explain this C code? I found it in the internet and im using it on a project, but it seems too complicated for me because i studied C++, and not C. Thank you all :) T...