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

Bingo! I told it was for a mod, Well it was about you. I tried up-votes two times(Not consecutive) and they just disappeared... It only happened with you so-far...

The system obviously doesn't me to get a swelled head. I'll start leaking brain all over the keyboard...

And tried up-voting two of your posts today, it worked.

Yay! Bigger rep numbers! I feel the swelling!!! :icon_mrgreen:

jonsca commented: That's just a pimple.... +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

who told you that 121 is a prime number oh please

If it did anything useful, your program would...

besides the code i have written works perfectly fine and i have tested it a hundred times

Really? I entered 130 and it output 32. How is that useful?
I added a cout to display the prime numbers it calculates and got

Enter thenumber till the check should go200
11  13  17  19  23  29  31  37  41  43  47  53  59  61  67  71  73  79  83  89
97  101  103  107  109  113  [B]121[/B]  127  131  137  139  [B]143[/B]  149  151  157  163  
167  [B]169[/B]  173  179  181  [B]187[/B]  191  193  197  199
50Press any key to continue . . .

Where's 2, 3, 5, and 7? What is 121, 143, 169, and 187 doing in the list? And what the heck is 50????

It runs fine, but the answers are completely wrong... Therefore it's useless.

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

Sure, they'd have to provide a driver (that was included in my 20 line estimate :) ).

We can't even get them to post with CODE tags and properly formatted! How are we going to get them to write a driver, too? Most of these people think a driver sits in a Toyota, not a computer. :icon_wink:

AndreRet commented: lol, indeed +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

But then again, in code snippets you are supposed to post correctly working tested code to begin with. Not broken code that needs a web-based compiler to fix.

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

Why not explain how to format the code properly so the OP can find his own mismatched braces? :icon_wink:

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

#1) What zeroliken said
#2) It's C++. Why are you using the terrible and dangerous C function gets() ? Use getline() .
#3) cin is your problem. Reading an int leaves the NEWLINE in the input buffer. The solution has been explained many many times on this site -- do a search.

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

You've been waiting 4 years to get back to this program?

No wait... First post -- resurrecting an old thread -- for no reason other than stating something doesn't work, but not explaining what doesn't work.

FAIL!!

Start your own thread and ask a real question.

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

4 resurrections... Great.

looping statements
if n=5, output
********
******
****
***
*

plz answer :(

... and with a gimme the code question -- how lazy.

Closed.

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

And where do you state you were in HS? You're the one that mentioned "the author is currently working at Microsoft" with no timeline, explanation, etc. to let us know you wrote it years before.

Who's the moron now? Maybe you should have left a 5-year-old thread stay buried.

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

My question is. how do i calculate the prime factors like if I enter 30 the response will be: 2, 3, 5.

I have a program that works using recursive functions but the exercise is asking to modify it without recursion.

1) Throw away the program that uses recursion.
2) Figure out how to calculate the prime factors on paper.
3) Write down the steps used. Test the steps with many values.
4) Convert those steps into code.

Do not skip any of the above steps. Especially #3.

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

Use getch() function defined in conio.h thereby you can avoid using scanf() to hold the output screen.

Very bad suggestion. getch() is
1) not portable
2) not Standard C
3) defined in very few compilers
The appropriate function to use is getchar() because it is
1) portable
2) Standard C
3) defined in all compilers

But his this case neither solution will appear to work since the NEWLINE from the last input is still in the buffer waiting to be read.

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

wonder if there is a way to just not allow certain words in the subject line? (help, urgent, ect..) im also not versed on websites (barely understanding vb) but, just an idea is all (and not really sure if its a good one LOL)

What part of

Hold your suggestions for just a bit longer :)

did you not understand? :icon_rolleyes:

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

No, it's because of undefined behavior. See this

DJSAN10 commented: hey thnx.. +3
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Lots of problems in this code...

#include<stdio.h>
#include<conio.h>      // unnecessary, non-standard -- should not be used
#include<stdlib.h>
#include<string.h>
#include<time.h>

void main()           // MAIN is not and never has been a 'void' -- see below

{
	int i[100];   // create an array from i[0] to i[99]
	int j[100];
	int k;
	int m;
	clrscr();     // unnecessary, non-standard -- should not be used
	printf("Enter the number of questions needed:");
	scanf("%d",&m);
	if (m<=100);
	{

		i[100]=rand()%m;      // I only goes to 99 -- 100 is not part of the array
		printf("%d \n",i,rand()); // calculate and print a new random number. Among other problems.

		j[100]=rand()%m;      // see 'I' above
		printf("%d",j,rand());

		i[100]=rand()%m;      // You are replacing the value above
		printf("%d \n",i,rand());

		j[100]=rand()%m;      // same
		printf("%d",j,rand());
	}


	getch();  // non-standard -- should not be used.  GETCHAR() is made for this
}

void main() -- See this

I want to generate random numbers when I press the amount. i.e. If i enter 50, then it should generate 50 random numbers between 1-100.

How can you generate 50 values without a loop? You only generate 2 values for each array, and don't even store them in the arrays.

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

The aim is simple: Input a string from the user, input a word that is to be searched in the string, and return "Found" or "Not found"

I have worked down the following code, and it works.

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

void main ()
{
	char para[200], word[20];
	int i=0, c=0;
	
	cout<<"\nEnter a paragraph: ";
	gets (para);
	
	cout<<"\nEnter the word you want to search: ";
	gets (word);
	
	while (para[i]!='\0')
	{
		if (para[i]==word[c] && word[c]!='\0' && para[i]!=' ')
		c++;

		else
		c=0;
		
		i++;
	}
	
	if (c==strlen(word))
	cout<<"\nWord found"<<endl;

	else
	cout<<"\nWord not found"<<endl;
}

I want to do it without having to use the strlen() function but I'm clueless. I don't want to use any library function for the search of the word in the string.

Edit: I could also count the number of letters in the character array 'word' and store it in an integer, then compare c with that integer, instead of using strlen().

Is there any other entirely different approach for achieving this?

1) Read this about void main() .
2) Read this about gets() .
3) Just use a loop to count the characters in word up to the \0.

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

[boilerplate_help_info]

Posting requests for help must be well thought out if you want help quickly and correctly.  Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful?  Check your post with these checkpoints - what is it [i]you[/i] missed:
[list=1]
[*]Ask a question that can be answered. Do not ask
- What's wrong with my code?
- Why doesn't this work?
- Anything else that does not give us useful information.
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- see this
- Use CODE Tags so your formatting is preserved.
If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
[*]If you have errors, post them! We can't see your screen.  We can't read your mind. You need to tell us what happened.
[*]Do [b]not[/b] ask for code. We are not a coding service. We will help you fix your code. 
    If anyone posts working code for you, they are a …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Look at your loop definition. Look at the code. Compare variables.

Also, if you add num[i], num2[i], and carry, you get a value from 0 to 3. Look at your IFs to see if you do different things when you get 2. Or 1. etc. If you don't do different things, you probably don't need so many comparisons.

I'll bet you can compress that whole section (48-109) into less than 10 lines with a little thought.

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

Instead of using fgets() , use a FOR loop to read num numbers using scanf("%d"...) .

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

and the post number, too.

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

Hi, guys I am working on vb project, which will save client database.

I've done the coding of ADD, NEW, SAVE, EDIT button. Now, I am stuck at DELETE button. When I delete any particular client then I want my client_id (it's a column in my access database) should get updated (like if I have five clients in database and if I delete 3rd client, then the client_id should start from 1,2,3,4; not like 1,2,4,5)

No it shouldn't. Once assigned, a client ID should never be changed. It is their unique value used throughout the system. All records pertaining to that person should be using this number and not their name, so the change would be monumental in a 'real' database.

What do you think would happen in the real world if, when someone stops driving, all the driver's license numbers changed?

Netcode commented: lol +6
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Call computeSphere(r, &a, &v); & will pass the address of the variable and the value can be changed in the function.

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

Read the list 1 value at a time
Put them in the array where you need them to go.

[boilerplate_help_info]

Posting requests for help must be well thought out if you want help quickly and correctly.  Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful?  Check your post with these checkpoints - what is it [i]you[/i] missed:
[list=1]
[*]Ask a question that can be answered. Do not ask
- What's wrong with my code?
- Why doesn't this work?
- Anything else that does not give us useful information.
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- see this
- Use CODE Tags so your formatting is preserved.
If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
[*]If you have errors, post them! We can't see your screen.  We can't read your mind. You need to tell us what happened.
[*]Do [b]not[/b] ask for code. We are …
NathanOliver commented: I love this bolier plate help +10
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Use while (!myInfile1.eof()) in place of line 35 and also close file handler at line 70) myInfile1.close();

No, don't. Here's why ( feof() is the same as .eof()

Xaviorin commented: Great resource with thorough explanation +1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I may be repeating myself with this but what I THOUGHT

Customer.substr(currentcount,Customer.length()-currentcount+1);

meant was that after grabbing the string Customer:

Customer.length()-currentcount+1);

would take string Customer: "Bright, Rich, PC12K2RT, 10/21/2011" and remove the first value including the first comma and the next whitespace leaving "Rich, PC12K2RT, 10/21/2011"".

Then rinse and repeat until EOF

You are correct in assuming that it removes the first value, but you don't do anything with that changed string, therefore, you lost it. Just like the statement
customer - currentcount; correctly subtracts currentcount from customer, but the result is lost, since it isn't stored anywhere. You simply need to store the result:
whatever = Customer.substr(currentcount,Customer.length()-currentcount+1);

Xaviorin commented: put up with me for a long time... i appreciate it more then you know +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

It the Terra Nova colony messing with the time line...

jonsca commented: Okay, Captain Taylor... +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Hello guyz how r u all

Annoyed at people that use leet speek on a professional programming forum, which is against the rules.

i m new in programming

So? We all were.

can u help me plzz

You must be a certain age to be a member here, and this kiddie speak doesn't bode well. So maybe not.

can u tell me that how to arrange array elements in ascending in descending order in C++
e.g suppose we have an array of 6 elements.. let elements are 65289...i want to arrange them in ascending like 25689.... can anyone help me plzz.. its urgent.. thank u

Ahhh, and another urgent request with a do-it-for-me attitude. Read the member rules NOW!

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

Guys, I'm actually almost done. Basically what I have to do is to read from file with a list of words, sort them alphabetically and write them into another file.

Sounds good so far.

I am almost done, but the only thing is, the assignment says that we shouldn't change the case of words,

So don't change the case.

but I am changing everything to lowercase, ...

So don't.

...because I'm using arrays to compare letters.

Why does that necessitate changing the case?

Either you are under a misconception vis-a-vis the assignment
or
You haven't given us the entire picture vis-a-vis upper/lower case

Side thought --
When you compare, why not just compare the lower case values using tolower() ?

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

Why are you reading an int (ch) and testing as a character? It should be defined as a char.

What does letters do in your code if you increment it then immediately set it to 0?

Also see this ( feof() is identical to .eof() )
and this
and this

EDIT: I think I know where the problem lies: you need to use in.get() rather than the << operator to read in the characters. Here's a modified version of your code that ought to work correctly:

Come on, you know better than this...
And you are also wrong. >> works just fine.

Schol-R-LEA commented: I completely missed that! Thank you, that explains a lot. +7
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

YAY!!!!

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

This loop is giving me ridiculous output, and the one a post above is only working when my number is in the format xxx.xx

*sigh* Why can't you follow simple instructions?

for(int i = balance.length()-1; i>=0; i--) // OPEN OUTER LOOP
         {
            
            if (i==2)
            {
                outFile << balance[i]; //// where is this statement in my 
                                       //// instructions if [B]i=2[/B]?  And is [B]i=2[/B] 
                                       //// the correct test?  Does it give 2 
                                       //// decimal places or 3?
                outFile << '.';
            }
            if (balance[i]!='.')
            {
                outFile << balance[i];
            }
         }                                       //CLOSING OUTER FOR

It's damn close. You just added stuff I didn't have. And you didn't bother to actually think about the condition.


Then there's:

for(int i = balance.length()-1; i>=0; i--) // OPEN OUTER LOOP
         {
            int a = balance.length()-1;
            if (balance[i]=='.')
                {
                    i--;                   /// where is this statement in my instructions?

                    ///  Is any of this code in my instructions if the character is a '.'
                    outFile << balance[i]; 
                    if (i==2) 
                    outFile << '.';
                }
            else   /// There is no ELSE in my instructions
                {
                    outFile << balance[i];
                }
 
         }                                       //CLOSING OUTER FOR
         outFile << endl;

This isn't even an attempt at my easy solution...


Why do you have to make my simple instructions so complicated?

for(int i = balance.length()-1; i>=0; i--)
    {
        If i = x then  // x is the magic number representing 2 characters left
        {
            output the '.' 
        }
        If balance[i] is not '.'
        {
            output balance[i] …
Assassin7893 commented: awesome +1
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

What am I missing here?

2/3rds of my algorithm.

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

My questions were there to help you answer your question, not explain the loop to us.

And yea, i can be 2, it's the string length.

and where does the period go? In the 6th position? The 3rd? Or...?

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

Two possibilities:

Find the '.' and remove it. Reverse the number. Add the '.' back in.

Reverse the value. If the '.' is not in the proper position, switch characters until it's in the correct position. I.E., If your number reversed is
52.1232 switch the dot giving
521.232 and switch again
5212.32 and output the value.

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

1) Never use goto . Use a while loop instead.
2) Format your code properly. It's difficult to follow and mistakes are made with bad formatting.
3) Always call srand() once and only once, at the beginning of the program.
4) Never use system("cls"); while programming. It's hard to debug code and see what has happened when the screen clears. We recommend never using it because it's annoying to the user, but if you really need it, add it after the program is running -- not before.
5) Never use system("pause"); . Why call the operating system to pause a program when cin will do it, cin is part of the language, and it's portable.

ndeniche commented: Excellent tip on the clear screen +10
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

just use system("pause") in the end before return

Search for this terrible function call on this board and learn why we do not suggest it.

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

Yep... :icon_mrgreen:

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

Two resurrections of a 3-year old thread with worthless posts are enough. Closed.

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

Don't know. You didn't tell us.

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

i would like to change my username to : kirkspock952035

Oh please! No!!!

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

You should be talking to a lawyer. We aren't qualified for legal advice.

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

[boilerplate_help_info]

Posing requests for help must be well thought out if you want help quickly and correctly.  Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful?  Check your post with these checkpoints - what is it [i]you[/i] missed:
[list=1]
[*]Ask a question that can be answered. Do not ask
- What's wrong with my code?
- Why doesn't this work?
- Anything else that does not give us useful information
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- see this
- Use CODE Tags so your formatting is preserved.
If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
[*]If you have errors, post them! We can't see your screen.  We can't read your mind. You need to tell us what happened.
[*]Do [b]not[/b] ask for code. We are not a coding service. We will help you fix your code. 
    If anyone posts working code for you, they are a …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

1) get rid of conio.h
2) "Write a C++ program that reads a series of 12 temperatures (floating-point numbers)" -- does your code read?
3) you obviously haven't been taught yet how to format your code -- learn this quickly and well.
4) get away from the computer.

  1. Sit down with pencil and paper and go though your simple assignment and plan out what needs to be done. Step by step.
  2. When you get the step by step done, look at each step and break it down into smaller pieces.
  3. When you can't break it down any farther, write down 12 numbers -- this becomes your 'file' (make the numbers simple.
  4. Now, starting at the top of your steps, follow them.
  5. Do exactly what the step says to do. Do not do what you meant the step to do. If you need to do that, fix the step.
  6. When you can run through all the steps correctly and get the right answer, you are now ready to program.
  7. Convert all the steps into code.
  8. Now, run through the code line by line, just like the steps.
  9. When that works, go back to the computer and start programming.

Yes, this sounds like a pain. But this is programming. It's design and planning. You can't program what you haven't planned out -- you get a jumbled mess that doesn't work.

In your case, you don't know what to do. But the description …

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

a++ and ++a alone mean the same thing. When used in an equation, they are slightly different.

Run this and figure it out:

int a,b,c;

a = 5;
b = 5;

c = a++;
cout << "c=" << c << "  a=" >> a << endl;

c = ++b;
cout << "c=" << c << "  b=" >> b << endl;

It's quite easy to design a test like this to answer questions yourself...

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

OK, I see where HG is going, and I see the conundrum cwarn has. I myself have written tutorials on another site that are linked to by many people here. That seems to be OK because DW doesn't want those tutorials as they are posted elsewhere. But they seem to be useful.

But in cwarn's case, he owns the site and wrote the tutorials. Hmm... And he wants the site to be affiliated directly with DW.

Well then, Dani, check out at his site. If it meets your quality standards and the articles and tutorials in his wiki complements well what we have here, give him your blessing. If not, what does he need to do to come up to your standards?

IMO, there should be no problem with a quality site that can be used in tandem with the forums. It's just an extended community at that point... Like a cousin site so to speak :icon_wink:

cwarn23 commented: thanks for pointing that out +12
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

1. the last line is cut off

What causes you to exit the loop? Have you already output all the data when it exits?

2. not sure if i need to have < 20 or <= 20 for the limit.

Then you'll have to make a decision... There's an easy way to find out :icon_wink:

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

Instead of outputting a SPACE, add it to a string.
Before outputting a *, output that string.
Be sure to reset (clear) the string after output.

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

I will gladly be more specific; allow me to take this opportunity to remind ye' that YOU ARE POSTING C CODE IN A C++ FORUM. I don't go to a Java forum and post Pascal. I don't go to a C# forum and post QBasic. I don't go to McDonalds and ask for a Whopper. Why do people insist on posting C code up in here and expect results...???!

C is C++. When an instructor in the C++ course starts with the easier (to them) syntax of C, they teach C under the guise of C++. The student doesn't know any better so they post here. This is perfectly acceptable so stop getting you knickers in a snit. It's not worth it.

Clinton Portis commented: you said 'knickers' and 'wad' in the same sentence. +10
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Let's recap:

hi there)
guys , please tell me - is there any way to check that the standart input is empty or no.
big thanks in advance)

There's no portable way to do this without actually blocking for input.

in terms of programming philosophy you're really right.....i even haven't thought about it....but still - is there any good(with standard behaviour in different compilers and platforms) way to do this?

ok! so if we use construction

#ifdef 
#if defined(_WIN32) || defined (_WIN64) 
#include <windows.h>
	#define  IN_WINDOWS 1
#endif

     #ifdef  IN_WINDOWS
       // code	
     #else
       // code
     #endif

we check stdin for both of windows and linux? how to do this?)
or where can i read about it?) tell please)

No. If you want to do it, you'll need to use a non-portable method for each target environment.

Are you getting the message at all?

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

I'll let Paris Hilton know you think she's smarter and works harder than you do.

I see, you believe that the parents should not pass their wealth to their children. So what should they do with it? Should all the money you have left when you die go to the government? Interesting concept. Or maybe an aptitude test be given to the children and anyone with an aptitude less than, say, 462, gets no money?

So far your user name is lacking... :icon_wink:

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

Use fgets() . It clears the buffer and places the data into a char* of your choice. There's the input buffer you have total control over.

vedro-compota commented: +++++ +3