I need help with my c++ program/please

Hello I take a C++ college course and my program was due last week but I want to still finish it.
It is supposed to count the number of words a person inputs with the functions. I used num_word for the function and my_alpha and have loops and everything but the output screen just lets them input words and then it says the number of words read is 0. It always says zero. I need help, I don't want to fail and lose 4 credit hours and Im a senior in H.S.
djabstractAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

djabstractAuthor Commented:
I pray someone can get back at me by monday. This is too hard for me.
thanks.
0
ozoCommented:
How are you counting the words?
0
Lab_RatCommented:
Another 1 liner ozo?
I likes thems :)

Oooops... notify :)
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

KangaRooCommented:
Bad spot to place your C++ question, there is a C++ section. Anyway, it might be a good ide if you show us some of your code.
Maybe this could be done in one line...
0
Lab_RatCommented:
I think I remember that it has, with standard library nested function calls.
0
mflamCommented:
Send the code, I'll fix it. (Todays Monday, but in Israel I'm before ya...)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KangaRooCommented:
What the (Edited by Computer101) are you doing mflam?
0
azamiCommented:
Hard to say without looking at code, but:

If you are passing a variable for your count into a function that is supposed to increment it, you may be passing "by value".  In this case, the function is working with a copy of the variable, not the variable itself:

void f(int i)
{
    i++;    //this is just a copy
}

void main()
{
    int a = 0;
    cout << a << endl;
    f(a);
    cout << a << endl;    //still 0!
}

The above program makes a copy of a and passes it to f(), which then increments the copy and does not change a at all.

Pass a pointer or reference to the function instead.

(I know this is way late for this assignment, but I hope that djabstract is interested enough in software development to want the lesson anyway.)

If this is not the problem, I'd be glad to take a look at the code and make suggestions.
-Matthew
0
Lab_RatCommented:
void flumps(int &i)
{
    i++;    //this is the ORIGINAL
//               Sneaky Eh?;)
}

void main(void)
{
    int a = 0;
    cout << a << endl;
    flumps(a);
    cout << a << endl;    //Not 0!!!!
}

0
mflamCommented:
Sorry, I was new to forum.
Figured, just like myself, if I have a fixed program, I look at it, and understand it...

Anyways, it's left open...
I suppose for djabstract it's too late, but:
IMHO what he's looking for is a program that reads in words, and counts them.
The errors he/she has are probably:
1. Initializing the arrays.
2. Using vars instead of pointers.
3. Typo's, using the wrong variable name.
4. Problems with output.
5. Problems with strings.

We gotta see the code to find out where the errors are, and point them out.

In Pseudo code the answer would be:
// Variables: StringArray, count
// Functions: CountWords(StringArray)
// Initialize all variables
// Input from user
//   eg. cin >> StringArray
// count = CountWords(StringArray)
//  NOTE: use pointer
//  eg. if was defined stringArray[40]
//      use CountWords(stringArray)
/       equivalent to &stringArray[0]
// cout << count << endl;



0
KangaRooCommented:
No problem.
Agreed, djabstract we need to see your code before we can try to find the errors that may be in it.
0
sureshkumarCommented:
hi

Your problem counting the no. of words in the given string.Is it right?????
0
sureshkumarCommented:
hi

Your problem counting the no. of words in the given string.Is it right?????
0
sureshkumarCommented:
if that is your problem i am giving solution for that have a look.

# include<iostream.h>
# include<string.h>

int main()
{

char a[100];
int word=1;count,i;

cout<<"enter the string to terminate !";
cin.get();
cin.getline(a,1000,'!');

for(i=0;i<=1000;i++)
{
if(a[i]=='!')
{
break;
}
count=i;
}

for(i=0;i<=count;i++)
{
if(a[i]==' ')
{
word++;
}
}
cout<<"no of words is "<<word;
return 0;
}

for the further queries welcome
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.