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

I also discovered I have to precede every '*' symbol with a \ to do the multiply i.e. ./test 7 10 \* rather than just ./test 7 10 *otherwise it starts printing out stuff I don't want. If I don't use the \, argv would also print out my file names and other random ubuntu directories on the desktop and a bunch of other stuff that shouldn't be there :S, that doesn't look too good, since it looks like it's accessing other parts of memory and it could screw up the entire OS. Strange!

No, it's not random at all. In *nix, a command line parameter * means "all files" (like *.*) in the current directory.

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

I agree. AD commented as he saw it, explaining why he would suggest not doing it. Then you became belligerent and condescending.

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

Try reading your Private Messages. They are explained in the messages.

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

Never never NEVER NEVER change argv[] values. They are command line inputs, not to be modified by the program. Copy them to an internal buffer.

If you use strPointer 10 7 + then argv[1] = "10" argv[2] = "7" argv[3] = "+"
You might want to read this series if you want to use command line parameters.

HOWEVER if just do

./test (no argument this time)

output>

(blank prompt so I input)

10 7 +

then it displays


strPointer 10 7 +

Segmentation fault

so StrPointer is getting what it's suppose to get but the segmentation fault comes out
of nowhere. Earlier on it wouldn't even display that, it would just terminate

Well, what's the value of your required argv[1] ? If you don't have any value, what are you 'calculating'? StrPointer is not getting what it's supposed to.

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

Change cout to printf
Change cin to scanf
Change to the proper headers for C
Post using CODE Tags.

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

Looking back on your code, #1 is stop using TABs to indent. Use 4 SPACEs. Your IDE can be set to convert TABs to SPACEs. And be more consistent with your indentation. See this.

Also, before you even touch the computer, design the program in pieces on paper. Take each step needed in the program and break them down into smaller and smaller pieces. Once you get them small enough, program one main piece at a time. Test. Correct. Test again. When it works, add another piece.

For example, what's your input look like? How do you input that data? Where does it get stored? Do you have to convert it? How? Program it. Test it. Make sure it works.

Do not write the entire program and try to compile. You'll spend an hour typing it in and hours trying to figure out what's wrong. Rather spend the hour at your desk. Then spend minutes typing in a piece, and minutes testing to get it right. Then another few minutes typing in and another couple minutes getting that right.

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

Ok worked out most of the bugs but now win I compile it I get an undefined symbol error.

(14) unixs1 $ cc keyword.c
Undefined first referenced
symbol in file
getch keyword.o
ungetch keyword.o
ld: fatal: Symbol referencing errors. No output written to a.out

And this is exactly why we recommend that you guys should not use compiler-specific non-standard functions when you code. Those functions listed do not exist in your compiler. But do people listen? Noooooooooooo.... :icon_twisted:

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

i do know it's supposed to print each line of my array...

No it doesn't.

i understand what he gave me...

No you don't.

Look at it again.

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

That's because you refused to give us the information necessary to know what was going on. We had no input to understand what you were testing with, so how could we possibly know what numbers were in error. You didn't even bother to tell us what was wrong with the output -- just that it was wrong. So don't blame us for your lack of info. We asked for it.

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

excuse me i didn't understand what you had said. no what my teacher gave me he said its supposed to help with my cin statement.

OK, continue with the pulling of teeth:

So what's that code do? That's the first thing to understand if you want to use it.

Look at the code. Look up the parts you don't already know. You need to understand the code he gave you. Use your book and GOOGLE.

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

Those numbers look fine to me based on the data you've supplied.

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

So my question stands:
What is it that makes a 7 digit number different from, say, a 4 digit or 8 digit number?

Answer that and you have a good idea what you need to test for. Think number, not digits.

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

Why would you want to strlen() and integer? What is strlen() used for?

What is it that makes a 7 digit number different from, say, a 4 digit or 8 digit number?

But, if you are going to have a pin value ready for them to match, who cares if they enter 7 digits or not? If the pin doesn't match, it doesn't match.

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

So what does your output mean? What's wrong with it? Just posting a bunch of numbers with no explanation makes it impossible to help.

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

That's what the code does that your teacher gave you? It doesn't look big enough.

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

We have flag bad post. We have infractions. We have rep.

Maybe we need a button for whiner!

Steve Nelson commented: You should get one for your account +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

... post back with something like, "well, my function does this when I put inputs X, Y, and Z into it, but I'd expect it to do something else."

Almost. Post back with
"well, my function does this when I put inputs X, Y, and Z into it, but I'd expect it to do this instead."

We don't want you to just say "I expected it to do something different" like so many people do. Explain everything in detail.

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

Do you want to change an unsigned int into a signed negative number?

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

What does %d mean in a printf() statement?

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

It is close to impossible to answer a question that is not asked. And you didn't ask one. So, we don't know what to help with...

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

i am trying to write a program to play the Battleship game;It is not a homework problem just a practice problem.

Good program to practice on. Well done.

The instructions are: set up a coordinate grid, select your own ships and locations while the computer selects its own; launch missiles by entering coordinates and accept hits from the computer.

Yes, that's how BShip works -- for the most part.

Thanks :)

You're welcome.

Nick Evan commented: :) +16
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I know the how to fill a magic square but there is a problem in the code.

We don't...

The algorithm is like below:
1-Put number 1 at the second column of first row.
2-Put the next number one upper row and one behind column.
3-If the cell mentioned in the last step was full,put the numebr at one row below at the same column.

We still don't. Could you make this a little clearer, please?

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

Add a ; after your keytab structure.

On line 13 you don't have a type name (like int keytab[] )

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

#1) Why are you using a string to hold 1 hex character. Use a char.
#2) Make a loop instead of 16 nested IF statements.
#3) Why are you taking the substring of convert and loading it into convert? Isn't that like digging a hole and putting the dirt in the hole?

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

Look up string parsing.

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

You must first go without sleep for 36 hours before being subjected to numerous hard-hitting questions like 'What you did last Summer'...

But I already know what you did last summer! :icon_twisted:

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

PS I hope you have malloced memory for max

Why? Can't you just create the variable using double max; and pass in the address?

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

How is this spam? Just looks like a worthless post to me, not spam.

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

This program is to count the number of words,vowels and consonants of a string.Here is my code.Please post your comment.I do not know whether I need to change anything.

IF (code works as expected)
    why would changes be needed?
  else
    changes are needed

Now if you have a specific question....

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

I guess by
Reading lines that are not blank and stopping when a blank line is read.
Process the lines read.
Start again.

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

To be fair, he hijacked a thread in which the original poster posted the code he needed help on. That's the code he seems to want to convert, but it was unfinished in the first place. This thread was split from that hijacked thread, and since the only code posted was in the very first post, it didn't get moved. And why should it? It wasn't finished in the first place.

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

> Information was asked for, and it was not provided

May I respectfully disagree. If you ever participated in those stupid contests, you'd immediately realize what the OP is asking for. That said, OP doesn't seem to do it either.

Wrong. When asked for clarification, he regurgitated the requirements originally posted. Since I quoted them, I already knew them, and stated I did not understand them. To repost them was a complete waste of time and utterly worthless. They are now posted in the thread at least 4 times. By your disagreement you are stating "the more times you post the same information the clearer the information becomes. Good luck with that.

in the first input, user will enter a number suppose t
corresponding to that number i.e., t , a set of t different numbers are taken.
if the numbers are greater than 0 then they are added.
in the example posted:-
first input is 4
corresponding to 4, a set of 4 other numbers are taken i.e,( 5 , -5 , 6 , -1 )
since in the set only 5 and 6 are greater than 0, so they are added up.
and nothing to do with -5 and -1.
so finally output is 5+6=11
and the output displayed is 11.

Finally!!!! It's only taken 22 posts and 3 days!

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

Bro, we have no idea what your code looks like. And we are not a coding service! I don't believe you've tried anything.

You have been asked before to read the Member Rules. It's obvious you haven't or you would have seen
1) Do use clear and relevant titles for new threads, none of your thread titles is clear nor relevant
2) Do not hijack old threads by posting a new question as a reply to an old one which you did for this question
3) Do not write in all uppercase or use "leet", "txt" or "chatroom" speak which you did above
4 Do provide evidence of having done some work yourself if posting questions from schoolwork assignments, and saying "IM TRYING BUT IT'S NOT WORKING" doesn't qualify.

And always calling us bro is annoying at best.

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

Problem I see is an over complex concept.

Why dynamic arrays? They are harder to deal with and your plane size is fixed. How about seating[12][4] to make it easy on yourself. Note your instructions say "The data structure that is used to store Passenger objects must be array." No mention of dynamic.

Also, the instructions state "You must define and implement a class Passenger to model passenger objects and you must use the class in your program." Your passenger class models the airplane object, not the passenger. A passenger does not have 12 rows. It also says the class object must be an array. It doesn't say the class must contain arrays.

Just food for thought...

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

Yes, but as already said, why? We don't really need more speeches. And it looks like you're posting just to post. That is frowned on.

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

I said rewrite, not requote. Stating the exact same thing when told it doesn't make sense in the first place is completely worthless.

And an explanation of the sample output is helpful, since the numbers entered and the number output make no sense together.

nezachem commented: Can't you add 5 and 6? +0
Fbody commented: Last I checked, 4+5+6 is 15. +5
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Could you rewrite this so it actually makes sense? With sample output?

Given the set of integers, find the sum of all positive integers in it.
Input
t – number of test cases [t < 1000]
On each of next t lines given a integer N [-1000 <= N <= 1000]

Output
One integer equals to sum of all positive integers.

I think the problem is these instructions are difficult to understand.

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

Why can't you read the line into integer variables? Isn't that allowed?

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

I don't think anyone has noticed, but the assignment doesn't mention string nor character array anywhere. Where did you get the requirement to convert stuff to a string? Why not just read the values as integers and compare?

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

>>A "loop control variable" is used in a for statement. That's where you should not change the value to exit the loop.


To clarify, you're saying...

for(int i = 0; i < 10; i++)
{
    // code
    i = /* whatever */  // <--- bad
    // code
}

Correct?

IMO, yes. Using the OP's question directly, the loop would be:

for(int i = 0; i < 10; i++)
{
    // code to calculate val
    if (val == 15) i = 11;
    // code Keep going
}

is better served by

for(int i = 0; i < 10; i++)
{
    // code to calculate val
    if (val == 15) break;
    // code Keep going
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

IMO, each member does not need to be welcomed. If they don't post in the introductions forum, it doesn't seem to be necessary.

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

In this case it's perfectly fine. You don't really have what's called a loop counter. You have variables that are tested in the while statement.

A "loop control variable" is used in a for statement. That's where you should not change the value to exit the loop.

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

setprecision only affects the next write operation. So you can setprecision on the numbers you want to have a fixed precision on and don't use it for those that you don't want precision on.

Actually, setprecision() affects the stream, not just the next output. See this

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

Walt: He said he couldn't use std::string or getline().

Oh, sorry. I was blinded by the red

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

that's the code he gave me but i don't know how to apply it to my code. (will post below)

So what's that code do? That the first thing to understand if you want to use it.

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

The next thing to do is NOT assume each line will contain exactly 1000 chracters. All you have to do is loop until '\n' is encountered.

int i = 0;
    char buffer[255] = {0};
    while( in.get(buffer[i]) && buffer[i] != '\n')
    {
       ++i; 
    }

Or better yet, make your buffer a string array[5000]; and read one full line at a time with getline() rather than thousands of individual character reads.

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

IM TRYING BUT IT'S NOT WORKING :s

It's because on line 38 you have the wrong assignment and 86 is a wrong comparison.

The Psychic Programmer speaks...

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

So did you try

cout <<"Without setprecision: "<<number<<endl;
cout <<"With fixed and setprecision(3): " <<fixed <<setprecision(3) <<number <<endl;
cout <<"The variable number again: " <<setprecision(0) <<number;

That would be my logical test next.

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

Twice x="%d" has been mentioned. Respond.

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

You've been asked a couple other questions.