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

RTFM.

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?
[*]To [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 cheater. 
    If you use that code [i]you[/i] are a cheater.
[*]Do [b]not[/b] bore us with how new you are. We can tell by …
NathanOliver commented: Nice +10
alwaysLearning0 commented: well said. +5
Narue commented: I'm gonna steal this for the Read This First thread. ;) +17
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Reread your text on printf() format specifiers. Specifically the %f specifier.

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

Well, it works with Microsoft's latest and greatest compiler 16.00.30319.01 for 80x86
And it works with Gnu C compiler 4.5.2, with Gnu C 3.4.5
Borland's 5.5.1 C Compiler.
Microsoft's Compiler 12.00.8804
Borland's old Turbo C 2.01
Borland's C++ 5.82

I might have to dig out one of my four working Apple IIe's to find a compiler it doesn't work on.

Showing that multiple compilers do not follow the standard is not proof that it works for all compilers. It simply proves that the compilers don't follow the standard. And if you continue to rely on undefined behavior to work a certain way, I'd love to see what happens when you write some critical software for your job on a compiler that doesn't implement undefined behavior to your needs. It could be weeks before you remember this thread...

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?
[*]To [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 cheater. 
    If you use that code [i]you[/i] are a cheater.
[*]Do [b]not[/b] bore us with how new you are. We can tell by …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I was telling you what works and what doesnt, so maybe you could suggest something else.

So doing the process by hand and understanding the steps didn't work at all in the 20 minutes from my post to yours. Maybe more time would have helped.

Im not an expert this is an INTRO class.

Duh. I think we know that, otherwise you wouldn't have a problem with an easy task. I'm not being snide, this is an easy task and anyone that can't do it is obviously a beginner and hasn't yet grasped the techniques. I was there once, too.

And btw and when you say "we" didnt suggest it, what do you mean because if you look at the the second post in this thread i can clearly see someone posted .resize(),

Sorry, for some reason I didn't remember reading that post three days ago. And since I knew it was bad advice, I surely blanked it out.

so maybe suggest something that does work. I came on this site for help and you surely didnt give me any.

Actually, I have. You just didn't get it. Yet. So here's another try:

1) Copy all digits (and only the digits) from the phone number into another temp string.
2) Test the length of the temp string. Is it OK? If not, do whatever you're supposed to do.
3) Clear the original string.
4) Is the first character in temp a 1? If …

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

from C++ Reference

size_t find_first_of ( const string& str, size_t pos = 0 ) const;
size_t find_first_of ( const char* s, size_t pos, size_t n ) const;
size_t find_first_of ( const char* s, size_t pos = 0 ) const;
size_t find_first_of ( char c, size_t pos = 0 ) const;

Find character in string
Searches the string for any of the characters that are part of either str, s or c, and returns the position of the first occurrence in the string.

But Silly me find() has an overload for to search for an entire string within a string. It probably is faster to use than what I thought up.

Didn't realize that about find_first_of, not having used it. Thanks for the clarification. I was certainly thinking there was a method like find that did exactly what was needed. And there it is! :)

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

ok how would i format it so they all have the same amount of characters a regular phone number has (with or without a 1) wouldn't I have to figure that out first then put in a "-". because some of the strings ending character should be cut off if their too long.

You need to think about it. Sit at a desk with pencil and paper and do it.
Write down the steps you take to get the first phone number in the proper format.
Do the next phone number following the steps, adding more steps as you need.
When your steps can handle all the possibilities, put those steps into code.

i have tried phrase.resize() and that didnt do what i want as some numbers have 1- and some dont so it throws everything off

So? Since we didn't suggest it because we knew it wouldn't work... :icon_wink:

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

You have to look at the phone number character by character and add or remove characters to put it in the format you want. One suggestion is to

start at the end of the number
-- make sure there are 4 digits
-- make sure there's a -
-- then 3 digits
-- another hyphen
etc...
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Well you could do this

size_t pos = 0;
string sample = "The man went to the store.";
while ((pos = sample.find_first_of("o", pos)) != string::npos)
{
    if (sample.find_first_of("r", pos) == pos + 1)
        cout << "good";
}

Why?
Wouldn't sample.find_first_of("or", pos) do it in one statement instead of adding another .find plus an increment?

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

I still don't understand. You are talking about EOF. And you're writing a -1. Why? Is -1 part of the data? Or are you writing -1 thinking that's an EOF? It's not. EOF is EOF. It's what you get when you read past the End Of File. you don't need to help the system, it knows.

So take out all that EOF crap and post again.

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

Don't forget to close your file handle!

{
fclose(file);
printf("%s was opened successfully.\n", fileparam);
printf("Good\n");
system("pause");
}

Also, it is good practice to initialize all pointers to NULL:

FILE *file = NULL;

It's also good practice to explain why system("pause"); is a bad thing...

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

Agreed. And what's a wid? Is it some sort of elf or gnome? We speak English here.

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

Hi Narue, thanks for your response. As I mentioned in my OP, i tried to upload a small csv file but daniweb would not let me.... I can email it you however if you'd like?

How did you get your CODE in your post? Do the same thing with your data! Sheesh!

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

You already have an infraction warning. Are you really trying for a full infraction? Didn't you understand the message that states you should become familiar with the Member Rules? I suggest reading them NOW and start over with a clean thread.

Thread closed.

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

Contact the owners of Borland stuff -- http://www.embarcadero.com/.

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

I ended up having the input for the hours and minutes be seperate, not really what was required but it was the only thing that would fix the minutes error.

So I take it you found out why you got a 2 and fixed it. I'm assuming so because you didn't respond directly to my questions.

I need a repeat function so anyone who uses the program can repeat it as many times as they want. But I can't seem to put it somewhere so it works...It's not there because I haven't found an appropriate solution yet.

Well, it looks like you tried, not with a function but with a do-while, which is more appropriate than a function....

and I messed up my formating? :( I didn't even notice..

.... and the do-while is where you messed up your formatting.

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

You forgot to add graphics.lib to the compile.

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

Hello, I've been having problem with this problem since yesterday and i just recently started C++, so please don't judge. I have very confused to what the question is asking and how the C++ program will look like.

Effective January 1st of each year, Gabriela receives a 5% raise on
her previous year’s salary. She wants a program that calculates and
displays the amount of her annual raises for the next three years. The
program also should calculate and display her total salary for the
three years.

a. Create an IPO chart for the problem, and then desk-check the
algorithm using an annual salary of $10,000. (The raise amounts
are $500.00, $525.00, and $551.25. Th e total salary is $33,101.25.)

I honestly don't know how i would even start writing the code as i hae looked for examples in the book and none have a problem similar to this. But the chapter cover loops.

I know it sounds lame, and it's the last thing someone would think to do, but IMAO since you don't understand the problem at all, you need to have a discussion with your instructor.

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

After creating and writing the file, what are you expecting to read? Where's the file pointer after a write?

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

What happened to your formatting? You broke it...

The system pause was really part of my rough coding, I've redone the program so many times by the time I finally asked for help that the proper ways were just not what I wanted to go through at the time.

Excuses, excuses... :icon_wink:

I fixed most everything I am still having one strange problem the minutes are coming up as only 2 no matter what value I put in for it.

Not so strange. What variable gives you the 2? And where did you load a value into it?

One more thing I'd like to add is that I'm not quite sure where to put my repeat function. I've tried it in several locations and it doesn't seem to work anywhere.

What repeat function?

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

ayeshashahid, can't be done, next input will put in the nextline.

Since there is only one cin , there is no next input.

You should just ask for each grade individually. Print the test such as "Prelim" and then wait for input and <enter>. This could be the resulting program output:

And how does that help him align the output to the header he displayed :icon_rolleyes:

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

help please?

You think people live here? We'll get to your problem when we get to it.

please use only this library cause I don't know how to use other libraries ...

What library? I don't see any library!

What are you supposed to do about the width and 1 angle (required for a triangle)?
Or 2 angles (can also define a triangle)? Just make them up?

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

Please note this code is most likely terrible. It's very rough. And before anyone insults me I know I probably seem like an idiot and in programming I pretty much am.

The only one insulting you is you. You code is nicely modular. Each function is defined to do one job. It's formatted. All in all, good code.

The only problems are:
1) using namespace std; only needs to be at the top of the program
2) using system("pause"); -- there are better ways
3) Not accepting the return value crom calc() -- you returned a value but never put it anywhere (this is the fix)

Oh, yeah, and CODE Tags...

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

You don't have any space to store the file name read in. All you did is allocate a pointer but it doesn't point anywhere useful.

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

I have three methods that I wrote, readBinary(), writeBinary(), and Update(). The program compiles just fine, but it doesn't do it's intended job...

...

So that takes care of THAT. However, here is where I am stuck..

I have never used opcodes. But am doing my best in my attempts to do so. I have sort of an "update file" thats an .ascii. In theory, it's supposed to have instructions and records about those instructions to add to the .bin file.

...

Like I said, my code compiles but I cannot seem to get it to work? I do not want handouts/the answers; I would actually prefer the opposite. I want to learn how to do this so maybe some pseudo code comments can help me out? In advance, thank you SO much for your time!

After all that, you might want to tell us what's wrong, not just say it doesn't work. How do we know what to look for?

Also, you might want to format your code better so the rest of us can follow it.

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

Any idea what "a problem with the dis[0][0]" is? Since I didn't run the program I can't tell what it might be.

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

After you read phrase and output it you throw it away and start reading the file again.

Instead, just look at each character in phrase and use each character in your switch. You also need to loop on the characters in phrase, not inputting to the end of the file.

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

can you pls give me a link to where i can download a free turbo c?

Try This

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

Mind giving us useful information? Like what it does wrong?

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

What does this mean?

fprintf(fp,"\n%d\n",-1); //as we are dealing with int so explicit EOF is neede
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

do you understand the concept of sentences and punctuation it doesn't look like it if you are requesting help you need to make sure people can understand you thats why english uses the concept of sentences and uses punctuation its so you can communicate correctly your needs that way you wont be misunderstood

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

Try outputting more values so you can see if all the variables contain the expected values.

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

Must I use a for loop?

Yes.

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

Reread what I wrote. It tells you to do something specific. Your post shows you did not read it carefully.

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

Please describe exactly what your file format is -- character by character in general terms (character digit etc...). Write that description down. Look carefully at it. What is your input statement missing given that format.

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

if you look at the original post the cursor X starts at the [0][0] at the start of every game and if it starts there than there cannot be a mine on that position.

The original post does not say this. And the code is far from doing it.

Write a truth table for your first IF statement and you'll will see why it's not doing what you want.

I was trying to see if there is a way so that when the iteration of the loop it needs to make sure a mine is placed on [0][0].

1) if you want to make sure a mine is at 0,0 just place one there. You will have to do a LOT of random calls to make sure you get two 0 values.
2) If X starts at 0,0 why would you want a mine there? Doesn't that make an immediate loss?

I need to check on the second,third and fourth iteration of the loop. i thought of the condition in the while loop
while(mineField[a] == 'M') and making it != will make it an infinite loop.

Yes, != will definitely make it an infinite loop, since the location is guaranteed to be 'M'. That guarantee make the IF worthless. It's always true so you will always place another mine. So you will place 8 mines -- but with no guarantee they will be in 8 separate locations. You might place mines on top of …

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

Moody, aren't you? After that rant I'm still wondering what the post is for since not one question was asked. Just a tantrum posted.

Now you're frustrated :icon_wink:

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

I have written a function to place mines. I need 'X' to be in array position [0][0] I cannot randomize so it does not overlap the mines b/c I can have only four mines in a [4][5] array.

The problem I am having so that it checks to see if it is not already occupied and something with the 2nd if statement

See the comments:

void placeMines(char mineField[][5])
{
	int z;
	
	for(z = 0; z <4; z++)
	{

		int a, b;

		a = rand() % 4;
		b = rand() % 5;

		if(a != 0 && b != 0)   // What is this for? 
		{                      // It seems to be useless to me.
			a = rand() % 4;
			b = rand() % 5;
		}
		
		mineField[a][b] = 'M';	// Change the value to M no matter 
                                        // what it is currently
		
		if(mineField[a][b] == 'M')  // This IF is ALWAYS true. You just 
                                            // changed the value
		{
			a = rand() % 4;
			b = rand() % 5;
			mineField[a][b] = 'M';
		}	

	}
				
}

Start with that and rethink this code.

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

First, don't just add comments detailing errors. Add information in the post. The comments in the code are used for additional help.

Second, I don't understand the comments. Please give more detail.

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

Hi folks,

int a=10,b=5,tmp;
tmp=a;
a=b;
b=tmp;

This is ordinary swap. I want to do this swap to the structure variables.

Make tmp an instance of the structure. Move each element as you swap.

And how to free the memory of tmp structure variable after swapping.

Why? It's not necessary.

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

(all constructive criticism welcome):

OK, here goes.

You have a function called userEntry(). Because of the name all the function should do is input data from the user and return the value(s).
Then, make a function to calculate the surface area and return the value.
Make another function to calculate the volume and return the value.
One last function to output the results.

This is modular programming and far superior to all-in-one programming. It's much easier to understand and debug. It will also alleviate the redefinition problem that has been pointed out.

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

Where else but Tennessee?!?! Sheesh!

Well, maybe Texas, Oklahoma, Mississippi, Alabama, Minnesota, Wyoming, Montana, Alaska, etc, etc, etc... :icon_rolleyes:

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

Interesting. I really don't know how to program something I simply do not understand. If you don't have the formula (or the steps), IMO it's impossible to program it.

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

Take the modulus 10000 of the date to get the year
Divide by 10000
Take the modulus 100 of what's left to get the day
Divide by 100
etc

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

We aren't asking you if you know how to program or write psuedocode. We're asking if you can calculate pi. Sitting at your desk. Without a computer.

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

Yeah I know its a terrible hack but I did mention it in the remarks.

Umm, yeah. It's so terrible let's not use it anymore. OK? :icon_wink:

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

So it's working, right?

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

Do you understand how to correctly do the problem by hand?

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

You cannot define a function ( RadiusofTwoSpheres ) in the middle of another function ( main() )