lotrsimp12345 37 Posting Pro in Training

it needs to make sure numbers aren't duplicate and are ordered. maybe change my cout statements to arrays?
Thanks.
This is what program is supposed to do
input
Q 1,2,3-5,6-7
output
do problem 1,2,3,4,5,6,7 of Q.

#include <iostream>
#include <cstdlib>
#include <sstream>
#include <string>
using namespace std;

int main()
{


    cout <<"enter the problemset and number""\n";
    //problems represents name and numbers
    string problems;
    char quote;
    char num;
    short number, number2;
    
    //gather name
    if(cin.peek()=='"' || cin.peek() == '\'')
    {
        cin >>quote;
        getline(cin,problems,quote);
    }
    else
    {
        while (!isdigit(cin.peek()) && !isspace(cin.peek()))
        {
         //   (char)cin.peek();
            problems += cin.get();
        }
    }


    //gather problem numbers
    //cin >> num;
    
        cin>>number;
        cout<<"very beginning\n"<<number;
        
    while(cin.peek() != '\n')
    {
        
        if(cin.peek()==',')
        {
            cin.ignore();
            cin >> ws;
            if(isdigit(cin.peek()))
            {
                cin>>number;
                cout<<"from comma\n"<<number<<"\n";
            }
        }
       
        else if(cin.peek()=='-')
        {
            cin.ignore();
            cin >> ws;
            if(isdigit(cin.peek()))
            {
                cin>>number2;
                cout<<"the value of # is\n"<<number2;
                   
                for(short a=number+1; a<=number2; a++)
                {
                    cout<<"next do #"<<a;
               
                }
            }
        }
        
    }
    
    //check for dulplicate and put in order
        
    // print them all out

    return 0;
}
lotrsimp12345 37 Posting Pro in Training

so insert something like this in my for loop?

if(int index=find_first_of(syll)
    {
         substring(0,index+1);
    }
lotrsimp12345 37 Posting Pro in Training
#include<iostream>

using namespace std;
int main()
{
string passage;
int space=0;
int sentence=0;
int word=0;
int character;
int index;
string delimeter=".:;!?";
string syllable;
string syll="aeiou";
cout<<"enter the passage to find out readability index";
getline(cin,passage);
    for (int  i = 0; i < passage.length(); i++)
    {
        //number of words
        if (isspace(passage[i]) )
        {        
            space++;
        }
        word=space+1;
        //number of sentences
        if(character=(passage.find_first_of(delimeter)))
        {
            passage.erase(0,character+1);
            sentence++;
        }
        //number of syllables
        
    //cin.get();
    }
    syllable=passage.c_str();
    cout<<"the syllable is"<<syllable;
    
    return 0;
}
lotrsimp12345 37 Posting Pro in Training

i have created a C string of my variables and guessing i need some king of loop to check each character after it gets it?

lotrsimp12345 37 Posting Pro in Training

it seems to work thank you.

lotrsimp12345 37 Posting Pro in Training

oh okay i will give that a try.

lotrsimp12345 37 Posting Pro in Training

so i would need to make a method to find the issentence?

lotrsimp12345 37 Posting Pro in Training

how do i find out # of sentences if they contain a :, :, ! or ?

lotrsimp12345 37 Posting Pro in Training

i am trying to find out the # of sentences they enter in a text. here's a link to the assignment.
http://home.earthlink.net/~craie/122/projects/diffrate.html

lotrsimp12345 37 Posting Pro in Training
#include<iostream>

using namespace std;
int main()
{
string passage;
int space=0;
int sentence=0;
int word=0;
int character;
cout<<"enter the passage to find out readability index";
getline(cin,passage);
    for (int  i = 0; i < passage.length(); i++)
    {
        //number of words
        if (isspace(passage[i]) )
        {        
            space++;
        }
        word=space+1;
        //number of sentences
        if(character[i]==(passage.find('.')))
        {
            passage.erase(0,character+1);
            sentence++;
        }
        
    }
    cout<<"the sentence is"<<sentence;
    cin.get();
    return 0;
}

it still gives me error. invalid type int[int]

lotrsimp12345 37 Posting Pro in Training

why doesn't the or operator work here? when i try to include semicolon.

lotrsimp12345 37 Posting Pro in Training

can someone check if this makes sense to find # of sentences. i think it does.

#include<iostream>

using namespace std;
int main()
{
string passage;
int space=0;
int sentence=0;
int word=0;
int character;
cout<<"enter the passage to find out readability index";
getline(cin,passage);
    for (int  i = 0; i < passage.length(); i++)
    {
        //number of words
        if (isspace(passage[i]) )
        {
            space++;
        }
        word=space+1;
        //number of sentences
        if(character=(passage.find('.')))
        {
            passage.substr(0,character);
            passage.erase(0,character+1);
            sentence++;
            cout<<"should print out multiple";
        }
        
    }
    cout<<"the sentence is"<<sentence;
    //cin.get();
    return 0;
}
lotrsimp12345 37 Posting Pro in Training

so i find the period or whatever the sentence ends in. Then I create a substring from that and delete the part which contains the end character. Then i keep count of it.

lotrsimp12345 37 Posting Pro in Training

so my original problem still remains for anything which is 2 char or above for a number.

lotrsimp12345 37 Posting Pro in Training

thank you for your help. It works.

lotrsimp12345 37 Posting Pro in Training

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

lotrsimp12345 37 Posting Pro in Training

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;
    }
}
lotrsimp12345 37 Posting Pro in Training

the loop doesn't quite work for 2 digit numbers.

lotrsimp12345 37 Posting Pro in Training

don't believe so here's a link to problem.
http://home.earthlink.net/~craie/122/labs/seqlist.html
i need comma because i need to check for duplicates and make it into an ordered list.

lotrsimp12345 37 Posting Pro in Training

now how would i get a comma to appear between each of them. my updated code is

#include <iostream>
#include <cstdlib>
#include <sstream>
#include <string>
using namespace std;

int main()
{


    cout <<"enter the problemset and number""\n";
    //problems represents name and numbers
    string problems;
    char quote;
    char num;
    string number;
    
    //gather name
    if(cin.peek()=='"' || cin.peek() == '\'')
    {
        cin >>quote;
        getline(cin,problems,quote);
    }
    else
    {
        while (!isdigit(cin.peek()) && !isspace(cin.peek()))
        {
            (char)cin.peek();
            problems += cin.get();
        }
    }


    //gather problem numbers
    //cin >> num;
    char lastdigit=0;
    while(num != '\n'){
        
        cin.get(num);
        cout<<"very beginning\n"<<num;
        
        if(num==',')
        {
            if(isdigit(cin.peek()))
            {
                cin.get(num);
                cout<<"from comma\n"<<number<<"\n";
            }
        }
       
        else if(num=='-')
        {
            
            if(isdigit(cin.peek()))
            {
                cin.get(num);
                cout<<"the value of # is\n"<<num;
                   
                for(char a=lastdigit+1; a<num; a++)
                {
                    number = number + a;
                    lastdigit=num;                                                      
                }
            }
        }
        number=number+num;
        lastdigit=num;
    }
    
    cout<<"the final number is"<<number<<"\n"; 
        
    // print them all out

    return 0;
}
lotrsimp12345 37 Posting Pro in Training

thank you very much.

lotrsimp12345 37 Posting Pro in Training

i need the integers though because i want my final value to be 1,2,3,4,5 in this case. and it doens't like atoi.

lotrsimp12345 37 Posting Pro in Training

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.

lotrsimp12345 37 Posting Pro in Training

i can't figure out where the lastdigit which represenst beginning of the index which has a - would go to.
help would be appreciated.

lotrsimp12345 37 Posting Pro in Training

so input would be
Q1,2,3-5
output would be
do problems 1,2,3,4,5 of Q

#include <iostream>
#include <cstdlib>
#include <sstream>
#include <string>
using namespace std;

int main()
{


    cout <<"enter the problemset and number""\n";
    //problems represents name and numbers
    string problems;
    char quote;
    char num;
    string number;
    
    //gather name
    if(cin.peek()=='"' || cin.peek() == '\'')
    {
        cin >>quote;
        getline(cin,problems,quote);
    }
    else
    {
        while (!isdigit(cin.peek()) && !isspace(cin.peek()))
        {
            (char)cin.peek();
            problems += cin.get();
        }
    }


    //gather problem numbers
    //cin >> num;
    int lastdigit=0;
    while(num != '\n'){
        
        cin.get(num);
        cout<<"very beginning\n"<<num;
        
        if(num==',')
        {
            if(isdigit(cin.peek()))
            {
                cin.get(num);
                cout<<"from comma\n"<<number<<"\n";
            }
        }
       
        else if(num=='-')
        {
            
            if(isdigit(cin.peek()))
            {
                cin.get(num);
                cout<<"the value of # is\n"<<num;
                for(int a=lastdigit; a<num; a++)
                {
                }
            }
        }
        number=number+num;
    }
    
    cout<<"the final number is"<<number<<"\n"; 
        
    // print them all out

    return 0;
}
lotrsimp12345 37 Posting Pro in Training
#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;
}
Sky Diploma 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
Nick Evan commented: It's no an answer Sky, this is the OP +19
lotrsimp12345 37 Posting Pro in Training

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

lotrsimp12345 37 Posting Pro in Training

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;
}
lotrsimp12345 37 Posting Pro in Training

i got it to work. had to change some properties of how is built.

lotrsimp12345 37 Posting Pro in Training

yea it compiles in one file. But i need library.

lotrsimp12345 37 Posting Pro in Training

undefined reference to 'test::alternate(int)'

lotrsimp12345 37 Posting Pro in Training

nope it isn't solved.

lotrsimp12345 37 Posting Pro in Training

thanks for help.

lotrsimp12345 37 Posting Pro in Training

that still doesn't solve my original issue.

lotrsimp12345 37 Posting Pro in Training

modified my implementation

#include <iostream>
#include <cctype>
#include <cstdlib>
using namespace std;
#include "libro.h"

int test::alternate(int width)
{
    //for odd, 3 char-ellipsis
    if(width%2==1)
    {
        if(width)
        {
         keep=width-3;
        }
    }
    //for even, 4 char-ellipsis
    else if(width%2==0)
    {
        if(width)
        {
        keep=width-4;
        }
    }

    keep_per_end=keep/2;
    return keep_per_end;
}
lotrsimp12345 37 Posting Pro in Training

in my main it doesn't like ab.alternate(length);

lotrsimp12345 37 Posting Pro in Training

my problem is that it doesn't return keep_per_end, my program doesn't compile

lotrsimp12345 37 Posting Pro in Training

//main

#include <iostream>
#include <cstdlib>
using namespace std;
#include "libro.h"
int main()
{
    test ab;
    cout<<"enter width limit";
    int length;
    cin>>length;
    ab.alternate(length);
}
lotrsimp12345 37 Posting Pro in Training
lotrsimp12345 37 Posting Pro in Training

the function is supposed to find out the number of characters at each end of a string it is supposed to store. and insert ... if odd and .... if even

lotrsimp12345 37 Posting Pro in Training

changed my code on top.

lotrsimp12345 37 Posting Pro in Training

ab is not right? in my main?

lotrsimp12345 37 Posting Pro in Training

//main

#include <iostream>
#include <cstdlib>
using namespace std;
#include "libro.h"
int main()
{
    test ab;
    cout<<"enter width limit";
    int length;
    cin>>length;
    ab.alternate(length);
}

//implementation

#include <iostream>
#include <cctype>
#include <cstdlib>
using namespace std;
#include "libro.h"

int test::alternate(int width)
{
    //for odd, 3 char-ellipsis
    if(width%2==1)
    {
         keep=width-3;
    }
    //for even, 4 char-ellipsis
    else if(width%2==0)
    {
        keep=width-4;
    }

    return keep_per_end=keep/2;
}

//interface

#ifndef LIBRO_H_INCLUDED
#define LIBRO_H_INCLUDED
#include <iostream>
using namespace std;

class test
{
    public:
    //check if even or odd 
    int alternate(int width);
    int keep_per_end;
    int keep;
};
#endif // LIBRO_H_INCLUDED
lotrsimp12345 37 Posting Pro in Training

thanks for help but i haven't learnt about pointers so i need another way of doing the problem. Its okay though i will just ask him tom.

lotrsimp12345 37 Posting Pro in Training

yea basically he only wants me to use c-string and string. Here's a link to what he wants me to do. Maybe i am supposed to read the sentence as a string.
http://home.earthlink.net/~craie/122/labs/strfind.html

lotrsimp12345 37 Posting Pro in Training

most recent code

//main

#include <iostream>
#include <cstdlib>
using namespace std;
#include "strextra.h"

int main()
{
    Search a;
    cout<<"enter max number of characters in the sentence";
    int number;
    cin>>number;
    cout<<"enter a sentence";
    string mycstring;
    cin>>mycstring;
    cout<<"my string is\n"<<mycstring<<"\n";
    cout<<"enter the character you are trying to find in the string above\n";
    char alpha;
    char lett[2];
    cin>>alpha;
    lett[0]=alpha;
    lett[1]='\0';
    cout<<lett[0]<<lett[1];
    a.find(mycstring, lett[0]);
}

//implementation

#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
#include "strextra.h"

int search::find(string mystring,char letter[0])
{
    return strchr(mystring,letter);
}

//interface

#ifndef STREXTRA_H_INCLUDED
#define STREXTRA_H_INCLUDED
#include <iostream>

using namespace std;

class Search
{
    public:
    int find(string mystring,char letter[0]);
    int find(char mystring,string word);

};

#endif // STREXTRA_H_INCLUDED
lotrsimp12345 37 Posting Pro in Training

so i am just going to have them read in a string for the input of the sentence and a c-string for the char they are trying to find.

lotrsimp12345 37 Posting Pro in Training

see i have a teacher but no lecture so basically i have to teach myself.

lotrsimp12345 37 Posting Pro in Training

i am really confused now.

lotrsimp12345 37 Posting Pro in Training

oh k now it makes sense. And with the methods a.find i can't pass in a variable?