WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I just looked at your code. It is identical to mine. You are counting the number of BS's and not pushing, whereas I count the number of BS's and "don't discard". What does "don't discard" mean? In your code it means "push onto another stack". I left the definition open to include an array or string.

The problem with your code is you require linelength. But it's a stack. You have no idea what linelength is, and don't need to. Just pop the characters and when the stack is empty, you're done.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

One step at a time. Start with the menu.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I get no errors when I compile --- at least after removing StdAfx.h header.

What compiler? What O/S?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

A digital calculator in Lisp

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

The problem with that way is that one would need a counter since there could be multiple backspaces,

Of course. If you have multiple BS's, you need to know how many.

thus when adding new elements, one would use counter to check if it should be added or not. If you reverse the stack, then the emphasis is not on adding, but on popping, that is instead of having to worry about whether to push the next value depending on how many backspaces were encountered, one would simply pop value if there was any.

Not following you. Original post states "array stack of characters that reads as follows:
Nn<-<-<-<-No <-w iz<-sthe<-<-<- the time.
" Therefore you have a stack that contains the information. You mention adding. Adding what? To where? The only thing you can do with the stack given is pop. There is no adding. Please explain what is lacking in my algo as a way to answer the original post. All popping. As a stack with data is supposed to do.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

The problem with FirstPerson's solution to reverse the stack is ... it's a stack. Stacks should not be manipulated in weird ways.

All you need to do is pop the values and you get the data in the proper order to perform the task. A pop gets the last value -- the '.'. The next pop gets '-', then '<'. This is simple. No overhead by reversing, no manipulating the stack in ways that stacks are not meant to be handled. No second or third stacks.

What part of my algorithm didn't make sense?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

is the better?[/url]

Much!!!! :)

well i was taught to use flushall(); when i have problem with gets() so i tried here[/url]

You were taught wrong.
1) See this about gets() .
2) See this about fflush() , which is a subset of fflushall() . Neither are guaranteed to work on input streams. Only output streams.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

If I understand you correctly, this thread offered no help at all and you decided to post another thread with the exact same question? This one's closed, continue with the original.

Plus, I gave you an (almost) perfect algorithm to do this task.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Start by formatting your code properly. You are probably getting lost, as I am, trying to decipher your code.

What us the flushall() supposed to be doing?

See this also.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

With a C++ IDE.

Spaces after all sentences. You are writing English! Do it properly!

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
//enter the given rang from keyboard
//u will get prime no from given range
//safwan hashmi
//email was here
//13-11-20103
//prime_rng.cpp
...

Very bad code:
1) terrible formatting - inconsistent
2) using code that at least 15 years old
3) using headers that ate at least 10 years old and have been replaced
4) using functions that no compiler uses to this day
5) Massaging your ego and giving out code that allows the OP to cheat

Good Job!

And thank you for posting your email address so web-bots can harvest it and add you to thousands of SPAM lists.

Ketsuekiame commented: Point well made +8
HASHMI007 commented: stupid +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

To return a value from the function and assign it to the integer a (as in your code):
1) Make the function an int instead of void
2) Set an integer variable val to some value in the function
3) return val; at the end of the function
4) Set a to the function in main() , like so: a = CountLetter("tttyuttt", 't'); I like the way you are writing small snippets of code to understand the program parts. Most people get so lost because they don't to this.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

what is the program of a simple c++ program of identifying if the number entered is prime or not using while loop..

It's a Prime Number Test Program.

is it possible to program without using bool??

yes.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Ummm, start at the end and move to the beginning, like you do on paper.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

1) Move the OutputData() function above addMoney()
2) Add prototypes (look it up) of your functions at the top of the program

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Format your code so it can be read and followed easily by others.

You calculated the values in the functions but never returned them.

[edit]Sorry, your formatting caused me to misread the code. See?[/edit]

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You are adding the numbers backwards. For the numbers 128 and 654 you are adding 6+1 first. When I learned the "usual pencil and paper addition algorithm" we started with 8+4 and if needed carried the overflow into the next addition of 2+5.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

And yet another poster that doesn't think telling us what's going wrong is worth knowing.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

And I'm having issues with my code. Can't seem to figure it out...

Any reason you won't tell us what those issues are? Do you think knowing them might help us understand?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Step backwards? You mean to say C# is better than C? How so?

If you feel C will be less restrictive than C#, sounds like a step forward to me.

I agree with your decision - it seems like a good one to me.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Write a program that teaches you one new thing. Then do that again. And again. And again. Practice.

Since you are a student, you are not yet a programmer anyway.
You've been at it for only two years (in school) so you aren't a programmer anyway.
Once you've been in a job for two years or so, you start to become a neo-programmer. It just takes practice time, and experience.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Just pop a character
If '-' then
{
   pop a character
   if '<' then 
   {
      increment bscount
      discard both characters
   }
   else
   {
      don't discard the characters
   }
}
else
{
    if bscount = 0
    {
       don't discard the character
    }
    else
    {
       discard the character
       decrement bscount
    }
}

That's what you need in a nutshell. What you are doing on a sequence of <-<-<- is popping the -, then blindly discarding the < and -. Next pop gets you <.

There's a little more logic to be added, but that will get you to 2nd base.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Thanks Walt!!

will you please give me some example where i can use fgets();

the link show how to use fgets() . Where you use it is obvious.

and you asked me about the index value in for loop:
i use "j=name;" the reason is if you give "j=0; then it will print whatever i scanf as you say will print from 0 to name (40 times or 50 time) i the the limit of my character array.

thanks again

I guess my questions are:
1) Why do you need a loop? What's it supposed to be doing?
2) You are looping from nameto name (whatever value i is) which is the same value. And you never initialized i, so it could be 23563 for all you know.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

As you reach a <-, count it in delcount. When you pop a regular character, if delcount > 0 throw the character away and decrement delcount.

As for the lone -, given the above sentence "this is a trial- new and improved" results in "this is a tri new and improved". You can't just blindly pop the <.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Sorry for the confusing title.

At least you tried... :icon_mrgreen:


Thing #1:

if (catchvar == '-') //if there is a '-', pop off the '<' and the letter its erasing
  {
    array.pop(discardvar);  
    array.pop(discardvar);
  }

What if the sentence is supposed to be "Now- the time is now!" when done?

Thing #2:
Pop the 'good characters' into a string and delete from there. When done, push them back. You don't want to edit the stack directly, which is what you're trying to do.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

scanf() only reads up to the first whitespace (Space, Tab, Return). You want to read the entire line. Use fgets() In general, you don't want to use scanf() to read strings anyway. Here's why.

Plus, think about your loop again. Do you really want the name entered to be your loop index?

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

By building on what WaltP said, I'm afraid even if you use an array for the strings, ur code will still be long, although not as sequential as you posted it. Solutions I can think of may be optimal but still not short.

I don't think 70 lines is that long. 38 lines of actual code from int main() to return 0;

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I am working on a project and i need to have the colume of 3 boxes but I keep getting errors when I try to compile.

Can anyone help and see what I am doing wrong?

Sure:
1) No formatting making the code difficult to follow.
2) No indication what the errors are so we don't know what to look for.
3) No indication where the errors are so we don't even know where to look.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

This is the 9th thread started by this member. Every one is just a program description. Never posted a second message with code, questions, nothing. In fact never one followup post.

He obviously is posting just to post and needs no help at all.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

You need to look up the file and directory routines of your compiler and/or operating system that's the starting points for this program then write some test programs to test what you are learning make them small and simple notice what happens when you don't bother writing in sentences just cramming all your sentences together makes it hard to understand you

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Not a clue. Can't read the error message, you don't tell us what line it's on, and your indenting is baaaad.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

No, I'm talking about the Do provide evidence of having done some work yourself if posting questions from schoolwork assignments section.

You must be under the mistaken impression we are a homework service. We are not. You do the work, we help solve problems - in a teaching manner, not a rewrite it for me manner.

>>Thing is, i need it for tomorrow evening
As the saying goes, "Poor Planning On Your Part Does Not Constitute An Emergency On Our Part".

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

i'm kinda beginner.

It shows. Beginners rarely bother to read the Member Rules nor the sticky post Read This Before Posting before asking a question.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I think you misunderstood me!! He was asking how to call the function1,which he did,in the if loop and about the above said problems..

Didn't misunderstand anything. I know what he asked.

1.Yes formatting is not there,but that won't give any compilation errors,would it?

No in and of itself. But bad formatting very often hides error that are obvious if the formatting was done. And why should I spend 20 minutes trying to read his code when, with formatting, I could find the error in a minute or two.

2.The return type is not mentioned in the main function but the default one ( void) will be taken up,as far as I know!

Try reading the link.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Exactly right - rta is not a word or phrase.

Royal Terpsichore Associates methinks... :icon_twisted:

But that's still not an anagram.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

it is still not working. Any suggestions on what I did wrong? :| I can compile it but the results are the same.

Are you kidding with this? Can't you figure out a better, more readable way to accomplish this?

{
if (a==b||a==c||a==d||b==c||b==d||c==d);
                                       ^ what does this do?
printf("same letter \n");
if(a!='a'||b!='a'||c!='a'||d!='a'||a!='b'||
   b!='b'||c!='b'||d!='b'||a!='c'||b!='c'||
   c!='c'||d!='c'||a!='d'||b!='d'||c!='d'||
   d!='d'||a!='e'||b!='e'||c!='e'||d!='e'||
   a!='g'||b!='g'||c!='g'||d!='g'||a!='l'||
   b!='l'||c!='l'||d!='l'||a!='m'||b!='m'||
   c!='m'||d!='m'||a!='p'||b!='p'||c!='p'||
   d!='p'||a!='r'||b!='r'||c!='r'||d!='r'||
   a!='s'||b!='s'||c!='s'||d!='s'||a!='t'||
   b!='t'||c!='t'||d!='t');
                          ^ what does this do?
printf("wrong letter \n");
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Here are the problems I see:
#include <conio.h> - non-standard, useless in your case
void main () - see this
clrscr() - old, non-standard, useless in your case
getch() - non-standard, use a standard C function like getchar() formatting - non-existent, see this
And lastly, telling us "it's not working" and making us try to figure out how it's not working. And explanation of how you can tell would be nice, like what numbers you enter and what answers you get. Something useful...

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

We can't understand what this is supposed to do either. There is no useful context.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

But you have already called it in the if loop! What's the problem?

What's the problem?
1) Formatting is non-existent.
2) main() is wrong.
3) fflush(stdin) is undefined.
4) Using scanf to read a character -- see the entire scanf series for maximum info.

That's what I see.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Tell you what. You comment each line whith what you think it means and we'll help you correct it.

And use CODE tags!!!

Salem commented: well said +17
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Team[0].atk is the first team

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Try using an array team Team[8] to make you coding easier and more compact. You won't need that godawful nested IF structure.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Please help on easy C++ recursion.. PLEEASE!

Don't beg. It makes you sound desperate and needy, and people will avoid your post.

Try printing out some values in the function to see what is happening as it runs.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

if (a==a||b==b||c==c||d==d) When is the variable a ever not equal to the variable a?
When is the variable b ever not equal to the variable b?
When is the variable c ever not equal to the variable c?
When is the variable d ever not equal to the variable d? else if(a&&b&&c&&d != 'a','b','c','d','e','g','l','m','p','r','s','t'); Look up the syntax for the IF statement.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Use arrays for the strings.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Look up function similar to findfirstfile() and findnextfile() for your compiler.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Compare them one by one. Count how many times there is a mismatch. If it's two or less, there's only one different value.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Best is the one you like best.

Anuradha Mandal commented: Not a good advise. +0