No looping statements

Write a program that prompts a user for a text made up of 5 words each ending with a /, and extracts and prints each word without the /. At each step you are required to print the extracted word, the remaining string, and the length of the remaining string. At the end of your program, the variable that contained the string with the 5 words should contain the empty string.

What to do
Here is a general description of what the program is to do.
1. Have a Welcome Banner in which your name(s) appear.
2. Prompt the user for a text
3. Read the string entered by the user into a single variable of type string
4. Extract the first word from the original string, store it into a different string variable, and print out both the extracted word and the remaining string. Include the length of the modified string. When printing out each word, and remaining string print a < at the beginning of the word/string and a > at the end of each. (See sample output in figure 2.)
5. Repeat steps 3 and 4 until you have printed the 5 words and the original string is empty.
6. Send a farewell message, so that the user knows that the program has terminated normally.
7. See sample output screen below. You output does not need to be formatted in exactly the same way. Just make sure the required information appears.
Restrictions: No looping statements allowed.
Ok what errors are you getting? Where are you stuck?
I don't know where to start, I'm new at this it's my first intro course
What assignments have you done for this class so far? What do you know how to do?
I don't know where to start, I'm new at this it's my first intro course


Problems are overwhelming when you look at them as a whole. Break it into smaller parts that you know how to do and work at those parts one at a time.

It even looks like your assignment already does that for you:

you wrote:
1. Have a Welcome Banner in which your name(s) appear.
2. Prompt the user for a text
3. Read the string entered by the user into a single variable of type string
...


Start by doing #1 (surely you know how to make a basic program that prints some text -- this can't be your first assignment).

Once that's working, add #2 to it.
Last edited on
im stuck at 3

i have a screenshot how can i post it here?
Last edited on
Here's what i have


#include <iostream>
#include <string>

using namespace std;

int main (int argc, const char * argv[])
{

// insert code here...
std::cout << "Welcome to Thomas's Word Splitter!!\n";


int input;
std::cout << "Please write five words with each being spereated by a /, including the last one and press enter:\n";

std::cin >> input;

extern istream cin;

return 0;
}


i get the feeling 40% of this is completely wrong lol
Last edited on
a) Your assignment says "read in a string", you include <string> and your cout says "write five words", but then you try to read in a single int? Rethink that part!

b) extern istream cin? That can't be right. I'd delete that if I were you.

c) Not entirely certain, but I think cin >> string will only read in a single word. Don't take my word for it though.

d) Isn't the proper genitive of Thomas Thomas', or is there an exception for names?
Also 5 "words" will not fit into a single integer variable, rethink that. Think string.

On a side note: As for Thomas' vs Thomas's ... it's really a matter of preference. Both are grammatically correct but usually where a 's would create an odd sound (like conscience's) the s after the apostrophe is omitted.
cin >> string will read until the first white space, so you'll either need to write that 5 times, or use getline()
http://www.mediafire.com/?51b499w8hl4b98p

there's a screenshot showing what it needs to look like

its question 2
Last edited on
Look at: http://www.cplusplus.com/reference/string/getline

Then look at the find() and substr() functions of the string class: http://www.cplusplus.com/reference/string/string/
what should i include?
1
2
#include <iostream> // for cin
#include <string>      // for getline() and string 


getline works like this:
1
2
string tmp;
getline(cin,tmp);
Topic archived. No new replies allowed.