English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

i need help with my comp sci hw:
here is the problem we have to solve(this is what the professor gave us. including the hint):
1. Write a program that prompts the user to enter a string containing a short English phrase with a single space between any two successive words. The program then outputs each word of the phrase separately. Test your program with the following input line “This is a test phrase” where the output for that input must be:
First word: This
Second word: is
Third word: a
Fourth word: test
Fifth word: phrase
Hint: You need to use various string manipulation functions.

this is what im trying to do:
#include
#include

using namespace std;

int main()
{
string inputstr;
cout << "Input Sentence= ";

getline(cin, inputstr);

int letter;
if letter==letter;
cout << letter;
if letter==' ';
cout << endl;
if letter=='\0';
cout << endl;


return 0;
}

he did not teach us about loops yet, do i dont think i can use those. i keep getting this error

2007-10-05 02:22:27 · 2 answers · asked by Rock Lee 3 in Computers & Internet Programming & Design

2 answers

if letter==letter;
will not get you anywhere.

I think that you need to investigate the use of the find function and the substr function.
No loops are involved but you need to think about a start and an end index pointer.

2007-10-05 02:33:58 · answer #1 · answered by AnalProgrammer 7 · 0 0

Conditions must be enclosed with parenthesis like
if(letter==letter). Also I think that you program should not work beacuse you need at least one while loop.
you can use string manipulation functions like strcpy(), strcat(), strcmp() with the loop

2007-10-05 03:20:07 · answer #2 · answered by Shariq (http://coinsindia.info) 5 · 0 0

fedest.com, questions and answers