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

0.000796327 is effectively 0. Look up the iomanip header and output exactly the number of decimals you need.

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

There's something I don't understand in your code:

cin >> result;
	if ( result == 12 )
	cout << "Well done, you're a star!" << endl;
        // why not use an ELSE here because if the above is false
	if ( result != 12 )  // it's obvious result is != 12
	cout << "Sorry, wrong answer!" << endl;
	if ( result < 12 )  // it's also obvious result is < 12 or ...
	cout << "Sorry, wrong answer!" << endl;
	if ( result > 12 )  // ... > 12 because it's !=
	cout << "Sorry, wrong answer!" << endl;
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Thanks for the help! What if I wanted 2 characters, for example, **?

Does this question have anything to do with your program? Or are you just asking?

What is it you really want to do?

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

Try it with 9.

You will find it is also even because in the loop when j=3, n%j = 0

This loop has nothing to do with odd/even. Where did you get this code?

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

I'm really sorry you've wasted an entire 15 minutes waiting for your personal help. Next time let us know when you're going to log in and we'll make sure everyone is here just for you.

Closed -- sheesh! There's just nobody here that has any suggestions for you at the moment. Do you honestly think that people are sitting here just waiting for you to post your question? Get real, kid. We have lives and this is all voluntary for us. Check other threads and see the times between posts.

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

> what is the value of info.regis?

That really doesn't matter, because the comparison at line 21 is guaranteed to yield true.

True -- but do you know why? And if you do, why don't you correct the OP rather than imply my post is of no help.

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

Who the h--l taught you that? He should be shot.

Please don't help anyone else. You are teaching very bad habits -- even worse than instructors teaching Turbo-C and conio.h

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

A one-character array is not a c-string. strcpy() only works on null-terminated strings. As sheff said, there is no need to define a 1-element array. Just define the value as a char and copy it to another char with =.

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

When you enter the loop, what is the value of info.regis?

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

You already have your input in individual characters. That's how a character array works.

With characters there is no such thing as 1 entry. It's always a character array.

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

4) There is no need to close the file, it is done by the destructor.

Bad form. Open a file? Close the file. Period.

Do you also never free dynamic memory because when the program exits it cleans up?

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

When you enter your number, the cin reads the number. But you also pressed ENTER. That's left in the input buffer for the next cin . Look up the .ignore() method. That will clear the buffer.

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

Stop begging! Jeez! You sound like a whiny child in love with the letter Z.

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

Does that compile? You need to write short sections of code, compile and test each as you go. Otherwise when you get 800 lines of uncompiled/untested code, you will have a nightmare of errors to try to fix.

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

Since you didn't bother to tell us what your new idea is, we can't help you. So far you've given us nothing to help with.

Start by rewriting the assignment into short statements telling you each of the individual requirements you need to consider. For example (these may be wrong):
1) Find the longest word
2) Find word with most vowels
3) Find word with most consecutive vowels
etc.

Then expand each to describe how to find/code these requirements.

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

Don't bother.

6 posts with no code tags = 1 warning and 5 infractions.
Fastest ban I've ever seen that wasn't for spam.

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

Have you come up with any ideas at all?

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

If you have no clue how to accomplish this, you'd better start reading your book fast. Start with your include s

Ancient Dragon commented: right :) +26
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

How did you solve this? I'm having basically the same problem.

What makes you think after two years this guy is just waiting around for you to ask this?

If it's the same problem, try reading the thread and get the same help he got.

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

Opening a file requires a C-style character array, not a C++ string. Jonsca has posted your answer. I just thought I add why.

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

I wish there was an option in the "What are you posting" for tutorials hehe. But I guess I will just have to right it here :). If anyone else has any pointers (pun intended) let me know ;).

Ok if your like me and were wondering how to accept command line arguements I am going to show you how (I couldn't find any detailed enough to explain to me anyways).

How about this?

jonsca commented: But that's written by some dude named WaltP at that other site. You must have stolen his username (and avatar) for this site +2
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I suggest displaying all the values before and after you try the insert.
Display the array, used, current_index, and any other variables that will help you figure out the problem.

Run the code in the debugger is also a good idea.

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

Look up the difference between int and char
Look up how an if statement is designed
Look up how to specify a character value vs integer value vs string value

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

and feed back says

error C2109: subscript requires array or pointer type

i have no idea what it means or how to go about solving it

It means that in order to have a subscript (i.e. ) you need to have an array, not a single integer

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

No, I have always used the same compiler. :icon_rolleyes:

Which is?

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

Posting Questions Lesson number 1:
"This is wrong" doesn't cut it. What is wrong? Always provide details. Only you know what happened, so you need to tell us
a) what happened
b) what should have happened.
Remember, we cannot see your screen. You need to post all information that is needed to figure out the problem.

In this case t and f are variables. You want characters 't' and 'f'

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

Dave and I both answered that.

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

cin.get() isn't doing anything, its just sitting in your code trying to look pretty and getting in the way :)

Not if you run the program in an IDE.

Yes, after adding "flush", the output came out! Thanks! Been doing C++ for a long while but never noticed this problem. Why didn't it happen anywhere else, since I have written many programs which ended with "endl" and never had problem?

P.S. logicmonster: cin.get() can't be the problem, since change about that makes no difference. Without that, any output would flash and go away.

Change compilers lately?

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

You're welcome in retrospect.

Why did you post this? What kind of response are you expecting? you didn't even ask a question.

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

1>d:\my documents\visual studio 2008\projects\idontknow\idontknow\ddd.cpp(13) : error C2228: left of '.Length' must have class/struct/union

1> type is 'int'

Since when does an int have a .Length member?

1>d:\my documents\visual studio 2008\projects\idontknow\idontknow\ddd.cpp(15) : error C2109: subscript requires array or pointer type

CardNumber is an int , not an array.

1>d:\my documents\visual studio 2008

\projects\idontknow\idontknow\ddd.cpp(18) : error C2065: 'cout' : undeclared identifier

Many of the rest are because you didn't specify the std namespace.

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

Well, look carefully at the error. What does it say is invalid?

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

Consistent formatting will solve these problems in moments.

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

This line is supposed to cause that error:

myArray[count].address=line.substr((myArr[1]+1),(myArr[2]-(myArr[1]+1)));

I can't understand why it says its out of range when the pos and length I supplied is valid.

Are you absolutely sure? Maybe you need to print out all the values you are using just before the statements to make sure.

Have you tried the debugger?

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

yeah thanks i ended up getting it
how do i determine if my variable is int double or float??

Ambiguous....

Q1: How can I tell if the variable is a double of float? Look at the definition. If it says float var; it's a float.

Q2: How can I tell if the variable should be a double of float? Does the variable need to have a decimal? If so, float .

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

Hows the formatting now?
Any other suggestions or corrections are welcome.

MUCH better.

You will find all your code will be easier to follow by always formatting. It helps us, too, when you need us to look at your code.

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

I don't see a problem. Maybe you should post the entire error, not paraphrase it.

Wonder if it has to do with using math.h instead of the C++ cmath. I doubt it, but cmath is the correct header.

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

okay well i have been modifying my code and this is what i currently have. I am using the program microsoft visual studio 2008 if thats clears anything up?

===
and the feed back that i recieve is:

1>d:\my documents\programming\assignments\assignment 2\p.3.17\p.3.17\p.3.17.cpp(22) : error C2065: 'salary' : undeclared identifier

1>d:\my documents\programming\assignments\assignment 2\p.3.17\p.3.17\p.3.17.cpp(23) : error C2065: 'itrate' : undeclared identifier

and im not sure how to declare it

Yes!!! Details.

You need to define salary and itrate before you can use them.

You defined itax, float itax; these others are no different. Just decide if they are floats, ints, or whatever.

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

I think I can identify where the problem is, I just have no idea how to go about fixing it or even trying something different.

Care to share where you think the problem is, or is it a secret?

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

I apologize for this. I've honestly been trying to explain where I'm at and what I'm having trouble with and providing my code for what I've done.

From your post, I'll update my issue to clarify.

I know it is inputting. I think that somewhere the value after the degree is missing (look at the example I supplied two posts up) and from there, the coefficients are being inputted improperly. I believe the area of concern is the for(int i=n+1;i>=0;i--) loop after the in>>n.

And you call this details? These are thoughts and guesses. "I believe" is a guess. "I think that somewhere" is a guess. There is not one detail in this post. Stop trying to explain. Show us.

Why didn't you mention what it is inputting? (contents of all the variables being input). Follow that by what you expected it to input (expected contents of all the variables)

Where is this information?

Did you try outputting each and every value read from the file to see if something is wrong in your loop?

Where did you give us this information?

And are you sure the coeff array is being loaded properly? output it after the loop.

And I don't see where this info is given either.

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

yeah i understand what you mean, if i had any clue what i was doing I'd tell you but im really not sure what it means

What what means? This is what I'm complaining about. You seem to have been given some kind of information, but you aren't sharing it. If the code is running, what did you type in, what did the code display, and what were you expecting to see?
If the code isn't running, why? What happened?

im pretty sure my else if statements are true so i think its something at the beginning/ending. when i go to compile the code it says path cannot be specified and im not sure what that means.

Neither are we if you don't tell us exactly what the compiler/program is telling you. Don't type it in, and don't paraphrase. Copy/paste like you did your code.

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

As for your code: #include <iostream.h> -- who's still teaching coding practices from the 1980's? The industry moved forward, you are being taught very old concepts which is crippling you. #include <conio.h> -- same with this. It's only good on a couple compilers and is non-standard. Will not work on most compilers. More stuff to unlearn when you upgrade to a current compiler. Again, a disservice to your education. void main () -- this is just wrong, and has been since the language was designed. See this clrscr(); -- conio.h problem. And you've just pinpointed the one and only compiler -- Turbo C/C++. Probably version 3 (1991) would be my guess. Note that only Turbo C++ has this command. What happens when you move forward to a compiler from 1996 or newer.
Also, this is an executable statement and cannot be before the definitions following it. itax=salary*6.0/100.0; -- why not 0.06 instead of 6/100? It's simpler.

And they need to teach you how to format your code. If your code was any more complex is would be too hard to follow. Learn formatting now before you move on. Trust me, it's extremely important.

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

Okay so I finished what i though was right but yeah, it doens't work here is what i have, just wondering if you could possibly tell me where it is not working cause like I mentioned I have just started a month ago and am not able to pick up easily on mistakes. this is what i have

This is frustrating -- sorry.

Why is it new people expect us to
1) read the code and try to understand what it's trying to do?
2) try to figure out what might be wrong with no clues?
3) come up with a solution?

You'd thing that the person with the problem who just ran the code and knows what went wrong would tell us what happened , rather than leaving it to us to guess.

Sorry for the rant, but this is the 5th post I've seen with "it's broke, tell me why" attitude in the last half hour.

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

What do you mean by suspicious?

Sorry bear with me. I've been staring at this code for near 20 hours this week in addition to a combined 60 hours of calc 3, statics, and chem 2. It all is blending together...

I know it's not inputting the value correctly, but I'm failing to understand the mistake that it's making. It looks right to me, but I know it's not.

And with this information, what can we say? Doesn't anyone that needs help understand the concept of details?

If you know it's not inputting properly, why didn't you mention that? Why didn't you mention what it is inputting? (contents of all the variables being input). Follow that by what you expected it to input (expected contents of all the variables)

Details are the only thing that helps, not vague descriptions. Save yourself another 4 hours of pain and loss of sleep.

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

1 / 1000 = 0. Integer math has no decimals.

You need floating point math: 1.0/1000.0 has decimals.

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

Did you try outputting each and every value read from the file to see if something is wrong in your loop? And are you sure the coeff array is being loaded properly? output it after the loop.

The loop looks suspicious to me.

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

You need to ask a question about what you don't understand. Not just post your assignment:
1) it looks like you want us to do it for you
2) we have no idea what you're having trouble with

When posting, details are more important than posting the assignment.

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

Good job. nicely formatted code, but you used conio.h . What grade did you get?

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

So what seems to be wrong? We aren't psychic...

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

If you stop yelling about it and make a descent thread with something like "The 10 things in C(++) you think are right, but aren't" and explain all the void main(), gets, clrscr, and other horrible things in detail, I'll consider making it a sticky, and you can just link to it.

You mean like I always do :icon_wink:


WaltP has his ups and downs :D

:icon_razz: plbbbbbb