Say I give out a question, what is the code to accept a long or even one word answer.
Example:
the program asks the question "What is the capital of the US?" How can you accept the answer.
Sorry this sounds dumb but I have only done number answers.
This is a discussion on Accepting Word/Sentence Answers within the C++ Programming forums, part of the General Programming Boards category; Say I give out a question, what is the code to accept a long or even one word answer. Example: ...
Say I give out a question, what is the code to accept a long or even one word answer.
Example:
the program asks the question "What is the capital of the US?" How can you accept the answer.
Sorry this sounds dumb but I have only done number answers.
You'd either use a character array, or a string.
character arrays go something like this:
strings are like this:Code:char capital[20]; //The brackets mean it's an array, the 20 means //that you can have up to 20 values in your array cin >> capital;
take a look hereCode:#include <string> //This is at the top of your program(before main) //in main do this: string capital; //This makes a string variable and calls it captial. cin >> capital; //This will get one word answers, but if there's a space it'll end there. //or getline(cin, capital); //This gets a whole line for the capital string.
http://www.cprogramming.com/tutorial.html
Last edited by System_159; 09-08-2006 at 02:58 PM.
Common questions are in the FAQ.
My best code is written with the delete key.