String Seriously Need Help

Hewlett-packard 4x dvd module mpeg decod...
April 5, 2010 at 12:48:42
Specs: Windows 7
Im not sure how to actually start the code... The code I have been doing keeps giving the incorrect output....

Prompt for and accept from the user a string that consists of eight (8) or more characters (without any blanks (spaces)). You are to continue to prompt and accept from the user a string until he successfully enters a string that has at least eight characters in it. Remember that you can determine the current length of a string with the notation stringname.length().

This is what I have so far:

#include <iostream>

int main() {
string Name;
string FirstName, LastName, MiddleName;
int NameLength;

cout << "Enter your first name: ";
cin >> FirstName;
cout << "Enter your last name: ";
cin >> LastName;
cout<< "Enter your middle name:";
cin>> MiddleName;

Name = LastName + ", " + FirstName + ", " + MiddleName;
cout << endl << "Your full name is: " << Name << endl;
if ( word1 < 8 chrs )
cout << "The string is to short. " << endl;

cout << "Enter a string at least 8 chrs long: " << endl;
cin >> word1

return 0;

See More: String Seriously Need Help

Report •

April 5, 2010 at 14:58:02
You don't seem to be following the assignment. It asks to prompt for a string that's at least 8 characters. You instead prompt for a first name, middle name and last name.

The assignment tells you exactly which method of std::string you need to call.

As it says "continue to prompt" that suggests you need to use a loop.

Report •

April 5, 2010 at 18:33:05
I would suggest a do-while loop.

do {
    your input stuff
} while (yourvar.length() < 8);

I would also suggest that you include <string> and add either "using namespace std;" below the includes or add "std::" to every "cout", "cin", "endl", and string variable declaration.

Report •

Related Solutions

Ask Question