Nevermind. No one answered but I got it now.
Well, someone didn't ask a question.
Nevermind. No one answered but I got it now.
Well, someone didn't ask a question.
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
If the file has variable length lines, no.
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.
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.
If pro is the opposite of con, what is the opposite of progress?
Fine.... As you wish.
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.
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.
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.
So use %u
for unsigned decimal instead of %d
for signed decimal. And declare your variable as unsigned
.
It's because there is a mistake in the program.
I think Siggy was onto something. Is the experiment really succeeding?
I have no idea why every post here is resurrecting an old thread with completely off topic questions, but it won't happen again...
Looks like a case of two different programs. Repost your code.
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.
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.
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.
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.
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.
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.
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()
Do you know what a void function is? Do you know what it returns?
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.
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?
This thread is done.
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.
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.
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.
Look at the code for the SetYear()
and GetYear()
routines. The answers are there.
Or are you supposed to write them?
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.
I'm sure Ahmed and Vicky had been sitting in front of their computers for two years just waiting for your response. Good Job.
Add another variable k to keep track of the an[] array position.
Or take a typing class.
Did you forget to read Announcement: We only give homework help to those who show effort? Or maybe Read Me: Read This Before Posting? Or even the all important Member Rules?
Define "won't run"
400 lines of code with no idea what we're looking for nor why is not going to happen easily.
How can we possibly tell you what's wrong with the code without seeing it?
d is the remainder of n/10. If n=32, d=2.
There is no d in the previous problem.
ans = fnAdd(a, b);
printf("%d + %d = %d \n", a, b, ans);
int fnAdd(int x, int y)
{
return (x+y);
}
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.
And????
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.
Here is what I have so far. Suggestions??
I suggest you explain the problem. We aren't psychic...
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()
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.
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.