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

Nevermind. No one answered but I got it now.

Well, someone didn't ask a question.

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

I don't know what you need there doesn't seem to be anything wrong with the getline statement what is wrong with the binary search you should really explain the problem so we understand the difficulty when you don't we just don't have any clear idea what might be wrong because we do not know the program only you do and what extra stuff are you talking about getline doesn't need a .ignore since it reads the entire line so there is nothing to ignore

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

If the file has variable length lines, no.

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

Hey all,
Currently I live in Maine, but as of late, I would like to take my family to IL and get a fresh start. The only problem is finding a tech job down there while still living here. Any tips on how I might go about doing this?

Thanks,
Hunter

The web is full of job postings. Search job sites and national contract houses.

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

that's why i never use them, braces
till is absolutely necessary
i hate to fight my way thru a forest of {{{{{{{}}}}}}}
and if i put to many of them i always got errors at my compilation
as i got them messed up.

So sad. You have bad formatting practices and blame the braces for errors rather than learn how to format well and understand how readable and maintainable your code could be. To each his own.

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

If pro is the opposite of con, what is the opposite of progress?

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

Fine.... As you wish.

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

You're asking for a solution to your homework? I'll give you a hint: Depth First Search.

Only good for a tree. I think you mean Permutations.

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

one things i dont understand is, while, cin encounters error(4th line), no push_back will take place,

Why not? If getline() returns an error, does the push back somehow just know there was an error and decide not to run? Is it linked to the getline() somehow I'm unaware?

so, the last item in the vector, will be the third line, which was only once push backed while cin was true.

But cin is TRUE after reading the 3rd line. It's only false after reading the 4th non-existent line -- which is immediately followed by the push back, error or not.

As for your "working" code, if you say so. It still looks like the same problem to me --

The IF status of cin is good
Attempt to read line -- error
Ignore error and continue with code anyway.

Whatever... Glad it works -- or appears to.

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

Good suggestion regarding variable names. It's neither here nor there, but it seems like in all but the last iteration of the loop, number is a number. "input" or something similar would be a good name.

No, number is an indicator. If you wish to be pedantic, all values in a computer are numbers -- even strings. But in this program number is used to indicate an error condition.

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

So use %u for unsigned decimal instead of %d for signed decimal. And declare your variable as unsigned .

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

It's because there is a mistake in the program.

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

I think Siggy was onto something. Is the experiment really succeeding?

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

I have no idea why every post here is resurrecting an old thread with completely off topic questions, but it won't happen again...

Salem commented: Hell Yeah!!!!! +19
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Looks like a case of two different programs. Repost your code.

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

When you have a function and need to scan for 2 different numbers, should the scanf be in the function or in the main() and why?

No, you should not put the input in the function. The function's purpose is to do calculations, so keep it simple. Maybe another function for input. But keep the different processes (input, calculation, output) separate. The more you do in the function, the harder it is to debug.

I'm trying to use the numbers to do calculations in my function. I want user input to get those 2 numbers.

Then you want the input before you call the calculate function.

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

The condition you have in the while() is not working.

But why not? Maybe an explanation is in order so the error does not happen again...

while(cin)
    {
        getline(cin, str);
        s_v.push_back(str);
    }

In this code, the loop exits after cin is in an error condition. After reading the last line, there is no error.

You now attempt to read the 4th line, which causes an error. But you don't check the error. str still has line 3 in it because nothing was read this time. So you now push back line 3 again. cin has an error now and the loop exits, but the damage is done. It's simply a case of not testing for the error at the proper time.

mitrmkar commented: "Why not" ... A good point there, kudos +5
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

If the missing values are always the last in the line, then as jonsca suggests read teach line using fgets() then use sscanf() to read the line into the variables.

But you also mention "a bad character". Do you mean there are letters in the input that will mess things up? If so, your task is much harder.

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

It's actually much more difficult than jephthah described.

In order to make sure the user types only the correct thing, you need to look at all the characters entered and test each character for validity (called parsing). Then you can decide to convert the values into integers and floats or tell the user his input is in the wrong format.

Although scanf() is not recommended as mentioned above, sscanf() is a good way to do the conversion after you've verified the input is in the proper format.

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

A clarity suggestion:

You are using a variable names number to control the loop. But number is not a number. It is an EOF indicator. I recommend all variables be named something that indicates their real use -- in this case maybe indicateEOF or EOFentered. Something like that.

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

Ahh, got it.

An integer function - int sub( ) - returns an integer
A float function - float sub( ) - returns a float
A void function - void sub( ) - returns nothing at all.

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

This was written quickly...I hope its correct..

Would it have taken long to give the code a quick test?

And there is no reason to call exit() every time you need to stop a program. A simple return will exit the program from main()

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
jonsca commented: No, I'm sorry the correct answer was 1010101010101111000110110101010101010101010101111 +2
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Do you know what a void function is? Do you know what it returns?

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

Gee, I'm sorry. I really don't need attitude, I need help. If you cannot reply in a decent manner, please don't reply.

No one gave you attitude. You have been notified about CODE tags before, and ignored the information.

/*O.k. I am down to a few less errors. I do not understand how to correct them, I have placed the ";" everywhere and it does not make a difference, in fact I get more errors. Still confused!

I see no ';' anywhere in this section:

total salesprice (after salestax) = sales_price + tax 
    months = months
	miles = miles1 + miles2
	payments = one + two /3

I also see no definitions for one, two, three, four which will cause errors. Basically what I see is a list of errors that did not come from the code posted.

As for the errors posted: c:\users\carole\documents\visual studio 2008\projects\compsci-assign11\compsci-assign11\compsci-assign11.cpp(57) : error C2143: syntax error : missing ';' before ':' Look at line 57. Is there a ';' that is missing? Probably from line 54-56 would be my guess.

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

Although not perfect, your formatting is much better. Thank you.

I am getting a compile error I do not understand on the line printf statement right below the end of the do while loop. It says printf identifier. Help?

That's because there is no such thing as a do while statement. It is a do-while loop:

do
{
    -- stuff to do --
} while (exit-condition);

Did you look it up before using it?

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

This thread is done.

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

No, it is not now 84. The only way to get 84 into Year is to write the code inside of SetYear() that actually loads the value from the parameter into the variable.

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

That's just as bad. Try clicking on the link. I put it there for a reason.

Or maybe you can explain how

int main()
        {
	      const int PEOPLE = 5, PRODUCTS = 6;
       double sales[ 5 ][ 6 ] = { 0.0 }, value;
        double totalSales, productSales[ 6 ] = { 0.0 };
		int salesPerson, product;
   	    int  i, j;
 
       salesPerson = 0;
	   product =0;
	   value = 0;

shows consistency in indentation.

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

Please use punctuation so we understand your question. Your 1st sentence is barely understandable.

Please read this, and note the title.

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

Please format your code consistently. It is very hard to follow when indenting is all over the place with unnecessary blank lines between every statement.

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

You only need 2 for loops, not 3. Figure out a different way to initialize and increment what you have called z.

Exactly. What you have will go through the loops 3600 times to move 60 values. A bit overkill.
Using an index does not have to be defined via a loop. You can just keep track of it without looping by adding one to it.

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

Look at the code for the SetYear() and GetYear() routines. The answers are there.

Or are you supposed to write them?

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

Of course not. Go back to your first post and fix it there.

You really need to think when programming. Not just throw something together for the pure joy of editing your code.

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

I'm sure Ahmed and Vicky had been sitting in front of their computers for two years just waiting for your response. Good Job.

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

Add another variable k to keep track of the an[] array position.

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

Or take a typing class.

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

NOT UNTIL YOU READ THIS!

And stop yelling. We can 'hear' you.

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

Define "won't run"

400 lines of code with no idea what we're looking for nor why is not going to happen easily.

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

How can we possibly tell you what's wrong with the code without seeing it?

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

d is the remainder of n/10. If n=32, d=2.
There is no d in the previous problem.

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
ans = fnAdd(a, b);
printf("%d + %d = %d \n", a, b, ans);
int fnAdd(int x, int y)
{
    return (x+y);
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Okay I changed the counter variable to maxValue and I now get an 3 output errors and one before for error, here is the code

You claim there are 3 errors. Do you think it might be helpful to let us know what they are? After 15 posts, you'd think you'd have posting help requests down by now.

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

And????

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

Thanks for the reply Salem. Unfortunately I get the exact same error message when I make the declaration "int i;" at the top of the function. So something else afoot.

Any more ideas?

Maybe you need to point out the exact line. Your compiler may not match the numbering on the forum.

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

Here is what I have so far. Suggestions??

I suggest you explain the problem. We aren't psychic...

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

A couple of while and for loops.

... in a generic function, or in main? Returning from main means your program is "done".

You did not answer Dave's question. Although we can surmise from your answer it's from main()

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
while (getchar() != '\n')
    ;

This code will read a character from the keyboard buffer.
If the character is not '\n' do it again. Keep it up until '\n' is read.

The body of the loop is empty because all the work is done with the getchar() function.

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

return x; will return the value x to the calling routine. If you called the function with rt = func(); rt will contain whatever x was. break; will immediately exit a loop even though the loop is not finished.

for (i=0; i<10; i++)
{
    --stuff--
    if (i == 7) break;
    --more stuff--
}

This loop will exit when i = 7. It won't run until i >= 10. And --more stuff-- will not be executed either.