here's my code, don't see why it doesn't print out

#include <iostream>

using namespace std;

int main()
{
    cout<<"enter a passage into input to find out how difficult it is to read\n";
    string passage;
    cin>>passage;
    char letter;
    int space=0;
    while(letter!='\n')
    {
        if(isspace(cin.peek())&&letter=='\n')
        {
            cout<<"from space";
            space=space++;
        }
    }
    cout<< space;
    return 0;
}

so it prints out but is an infinite loop, need to check if they do enter '\n' character how to do that?

#include <iostream>

using namespace std;

int main()
{
    cout<<"enter a passage into input to find out how difficult it is to read\n";
    string passage;
    cin>>passage;
    char letter;
    int space=0;
    while(letter!='\n')
    {
        cin.get(letter);
        while(letter=" ");
        //while(isspace(cin.peek())&&letter=='\n')
        {
            cin.get(letter);
            cout<<"the letter is"<<letter;
            space++;
        }
    }
    cout<< space;
    return 0;
}
commented: Bad Answer![color="red"]while(letter=" ");[/color] Firsltyyou are assigning a value to letter instead of comparing"==" and then another error is that you are comparing a char with a const char* -1
commented: It's no an answer Sky, this is the OP +19
#include<iostream.h>
#include<conio.h>
#include<stdio.h>

void main()
{
clrscr();
char st[25];
cout<<"Enter String:- ";
gets(st);

int n; 
n = strlen(st);
int i;
int count=0;
for(i=0;i<=n;i++)
{
         while(str[i] == NULL)
         {
                   count=count+1;
          }
}

cout<<endl<<"Space:-"<<count;

getch();
}
commented: Abbominative code. -1
commented: ...and no code-tags again -4

nirav99,

Use BB code tag. Source program must be surrounded with BB code tags: See # icon at toolbar and also read How to use bb code tags?.

basically i am trying to create a readibility index so i need the number of vowels, words and sentences. I am stuck on how to approach this.

okay...
thanks

cin>>passage;

cin would stop reading as soon as it encounters a space !
Use getline instead:

getline (cin  ,  passage)

while(letter!='\n')
    {
        cin.get(letter);
        while(letter=" ");  //<<extra character makes it redundant;) 
        //while(isspace(cin.peek())&&letter=='\n')
        {
            cin.get(letter);
            cout<<"the letter is"<<letter;
            space++;
        }
    }

Instead ,

for (int  i = 0 ; i < passage.length() ;i++)
    if (isspace(passage[i]) )
         space++;

gives me weird error of includes atleast one deprecated or antiquated header.
And it doesn't seem to capture # of spaces.

#include<iostream.h>

using namespace std;
int main()
{
string passage;
int space;
cout<<"enter the passage to find out readability index";
cin>>passage;
getline(cin,passage);
    for (int  i = 0; i < passage.length(); i++)
    {
        if (isspace(passage[i]) )
        {
            space++;
        }
        cout<<"the number of spaces is"<<space;
    }
}

Change <iostream.h> to <iostream>, that's the standard C++ way.

Also delete the line cin >>passage . You're already taking in input with getline(), so no need to do it twice.

And also change int space; to int space = 0; . How can your program ++ if it doesn't know the variable's initial value?

Also put this line: cout<<"the number of spaces is"<<space; outside your for loop. You only want to display this messsage once right?

[edit]

Also ( :) ) , you might want to put a cin.get() at the end of your loop (right after you output your message. This keeps the console open for you to read what the output of your program is. If you don't put it there, your console window will disappear to fast.
You could also run it from a console window you've already opened, but my guess is that you do not yet know how this works.

now it says comparison between unsigned and signed integer expressions
so do i say one is unsigned type?

I've editted my previous post, you might want to read it.

>> now it says comparison between unsigned and signed integer

It's right. This line : for (int i = 0; i < passage.length(); i++) compares an unsigned integer (returned by the function length(), with an signed integer (your int i)
To solve this warning, just change it to: for (unsigned int i = 0; i < passage.length(); i++)

thank you for your help. It works.

no no..
loop is not going infinite, loop is running equal to the numbers of character in a string which you have entered..
i have stored that character in integer variable " n " using " strlen(input string) " function.
and in case of "/n" i think it may not be consider as a member of string..

no no..
loop is not going infinite, loop is running equal to the numbers of character in a string which you have entered..
i have stored that character in integer variable " n " using " strlen(input string) " function.
and in case of "/n" i think it may not be consider as a member of string..

What the hell are you talking about?
Anyway: The problem was already solved, you should read all the replies before you make a reply yourself.

Mr xyz...
for your kind information..
i was solving his confutation and i think he may got it...
its non of your business..
and also mind your language, dont proud or shout to be "nearly a posting maven".
In past when u newly joined "daniweb" as i have joined yet, your situation might was like mine..
okay..

s

so it prints out but is an infinite loop, need to check if they do enter '\n' character how to do that?

no no..
loop is not going infinite, loop is running equal to the numbers of character in a string which you have entered..
i have stored that character in integer variable " n " using " strlen(input string) " function.
and in case of "/n" i think it may not be consider as a member of string..

Mr xyz...
for your kind information..
i was solving his confutation and i think he may got it...
its non of your business..

It's niek_e not xyz. Why is this non of my business? I helped the OP to solve the problem?

Mr xyz...
and also mind your language, dont proud or shout to be "nearly a posting maven".

"nearly a posting maven" is just a title I got for posting more then 2000 (?) posts. Just as your title is "newbie poster" because you haven't posted very much yet. Can't do anything about it, not my choice.

In past when u newly joined "daniweb" as i have joined yet, your situation might was like mine..
okay..

No, my situation wasn't like yours at all. I read the rules for example, which clearly state:
- don't give away homework
- use code-tags
- use proper language/grammar
- don't bump:

s

^ What?

Why did you repost your original post? It still doesn't make much sense, even if you post it twice.
- What strlen() are you talking about?
- "/n" is not the same as '\n'
- a character is not a member of a string

commented: Well stated. +18
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.