| | |
having trouble with if statement and string
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2008
Posts: 49
Reputation:
Solved Threads: 0
i have a code that you enter section after section. when your done, you type end, and it stops asking you to enter in stuff. My problem is, I can get it to detect when I type end.
here is my problem:
I see the problem here. it's saying that if the string "end" equals itself, then go into the if statement. but what I want to happen is if someone actually types end, and hits enter, I want it to be able to know. if they type anything else, then just keep going. how do i do that?
here is my problem:
C++ Syntax (Toggle Plain Text)
cout << "\n\n\nTo start, enter each section line per line, by entering a section, hitting enter, then the next section, enter, and so on. when you done, type end."; cin >> stringa; end = stringc; if (end = end) { cout<< "ok, you are now finished entering #'s\n\n"; } else { cout << "\nNext:\n"; cin >> stringb; end = stringc; if (end = end) { cout<< "ok, you are now finished entering #'s\n\n"; } else { cout << "\nNext:\n"; cin >> stringc; end = stringc; if (end = end) { cout<< "ok, you are now finished entering #'s\n\n"; } else { cout << "\nNext:\n"; cin >> stringd; }
I see the problem here. it's saying that if the string "end" equals itself, then go into the if statement. but what I want to happen is if someone actually types end, and hits enter, I want it to be able to know. if they type anything else, then just keep going. how do i do that?
•
•
Join Date: Nov 2007
Posts: 390
Reputation:
Solved Threads: 39
C++ Syntax (Toggle Plain Text)
if (stringa == "end")
•
•
Join Date: Oct 2008
Posts: 49
Reputation:
Solved Threads: 0
thanks. the "" was what i was missing. I used the ==, but it didnt work, so thats why i didnt place that in the code i showed you guys.
![]() |
Similar Threads
- Urgent Help With a SQL Where statement (MS SQL)
- Read string and use in switch statement (C++)
- Counting Spaces in a string (C++)
- Trouble getting code to compile (C++)
- Text printing is giving me trouble (C#)
- Element is undefined in a Java object of type class [Ljava.lang.String; referenced as (ColdFusion)
- error checking of user input (C++)
- If....else password statement (C++)
- Help w/Structs and 'For' loops (C++)
Other Threads in the C++ Forum
- Previous Thread: Round Up Round down(truncate)
- Next Thread: error in c++
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion convert count data database delete desktop developer directshow dll download dynamic encryption error file forms fstream function functions game generator getline givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory news node number output parameter pointer problem program programming project proxy python random read recursion recursive return string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets







...