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

Well I know that... I just don't know how to...

I tried something like this:

ofstream someFile("file.txt", ios_base::app);
    ifstream someOtherFile("file.txt");

but that didn't work either...

Then you did it wrong. Since you didn't bother to post the bad code, we can't very well help.

Before you just post more code and ask us to tell you what to do, think about it...
1) How do you open a file for writing? You seem to know this one OK.
2) Where do you need to open the file for writing? What lines of code does the file have to be open for?
3) How do you open a file for reading?
4) Where do you need to open the file for reading?

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

Im sorry for being a little messy. I finally figured out how to make the log10 function work. Unfortunately I still couldnt do the same for the factorial function. Maybe cuz I'm doing it the wrong way or maybe cuz im mistaking the meaning of the function. I still need help. Thanks

So what is the function meaning? And how do you do a factorial? And what are the limits (based on the computer)?

I've found if you don't know how something works it's impossible to program.

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

hey waltp, thanks for putting up with me, so I fixed one of the problems regarding having a $0 balance and the game would continue by using

bool exitswitch = false; // on the outside of the switch statement
exitswitch = true; // within the loop cased inside the switch
if(exitswitch == true) break; // in the switch

Great!!

now I'm not sure if that was a good way of doing it, but it works....
as for inputing a letter instead of a number, causing the program to loop endlessly, I'm guessing were back to conversions?

Yep...

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

append = opens the file without deleting whatever is in it.
choice

Wrong. Open at the end of the file for writing...

2 = checks the date that was entered when the program first opens, prints out the date, name and info if the date in the file is the same as the date that was entered in the program.

What does it do with the file? doesn't it read? Isn't that at odds with opening the file
a) at the end? What's it going to read?
b) for writing? How's it going to read?

Change where and how you are opening to file so you open it properly for the task you want to perform.

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

I think we should assume the rich "deserve" to be rich just because they are rich. And that telling them to give back to the services they or their ancestors benefited from to become rich is not "penalizing" them.

"Telling them" is penalizing them. The rich should -- and do -- give back to the community and the system on their own. The problem is everyone seems to think they should be taxed more simply because they have more. IMO that is wrong.

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

What I know about footy I learned from the dog in Footrot Flats! And Ol' Wal, of course...

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

I don't know why but WaltP has something against me, anyway, I'll just mark it as solved, thanks anyway

I do? Get a thicker skin. Sarcasm is rarely personal. Your post just gave such a wonderful opening for it, it would be rude not to jump on it... :icon_wink:

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

If it's beyond your current knowledge, put the task in the shelf for a few weeks and come back to it. You will probably have enough knowledge by then to start tackling the job.

Or search the forums. This has been answered a lot!

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

Compilers rarely say "There is an error". They usually tell you much more about the error so there's something useful to think about.

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

yea but you left out this =

And you found a way to do it then. Please post your solution so we all can learn from it...

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

Read all inputs as strings. Then test to see if all characters are digits and if so, convert to a number and continue. Otherwise, process an error.

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

Also, you should get rid of

void clrscr()
{
  system("cls");
}

because it's more annoying to the user than useful, and calling the system to execute an O/S command is expensive.

And as for:

void pause()
{
  system("echo.");system("echo.");system("pause");
}

3 calls to system? Just to do what

cout << "\n\n";
cin >> x;

does? And the above is completely standard!

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

Let's recap:

hi there)
guys , please tell me - is there any way to check that the standart input is empty or no.
big thanks in advance)

There's no portable way to do this without actually blocking for input.

in terms of programming philosophy you're really right.....i even haven't thought about it....but still - is there any good(with standard behaviour in different compilers and platforms) way to do this?

ok! so if we use construction

#ifdef 
#if defined(_WIN32) || defined (_WIN64) 
#include <windows.h>
	#define  IN_WINDOWS 1
#endif

     #ifdef  IN_WINDOWS
       // code	
     #else
       // code
     #endif

we check stdin for both of windows and linux? how to do this?)
or where can i read about it?) tell please)

No. If you want to do it, you'll need to use a non-portable method for each target environment.

Are you getting the message at all?

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

It obviously completely makes sense that people would rather post and wait hours for a response than do a search and get instant gratification, right? :)

Yep. Human nature....

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

Yes I have an old fashioned phone, and I have tried the *69 thing but doesn't work, that may be because I live in South Africa, any other solutions?

Hmmm let's see. South Africa. Phone. Ummmmm. Can't think of a thi... No Wait!!!! Call your phone company! Noooo, you'd have to be pretty stupid to not think of that. So obviously the phone company doesn't know. And if the phone company doesn't know it's not likely we would know since few of us live in Africa. Maybe the utilities commission, or the government knows. Sorry to hear about your phone company, though. I'd get another company that knows their system better. You might want to move to Spain.

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

I'll let Paris Hilton know you think she's smarter and works harder than you do.

I see, you believe that the parents should not pass their wealth to their children. So what should they do with it? Should all the money you have left when you die go to the government? Interesting concept. Or maybe an aptitude test be given to the children and anyone with an aptitude less than, say, 462, gets no money?

So far your user name is lacking... :icon_wink:

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

There's too little information for us to make even a guess at what you need. Sorry. Details, code, and design are missing from your question.

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

What does append mean? What does choice 2 do?

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?
[*]If you have errors, post them! We can't see your screen.  We can't read your mind. You need to tell us what happened.
[*]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 …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

If the site doesn't have any info, contact then directly.

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

Your response makes no sense. Input randomly and call the function have nothing in common.

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

Though I will ask the usual question: if these folks aren't searching the forum before starting new threads, what makes you think they'll read the stickies? ;)

Because when a new user comes to post a thread, they don't like to look through pages of pages of results to find one answer.

Did you miss the "search" -- i.e. use the SEARCH box?

They prefer to see the one link then click it for the answer. Very much like a sticky or a wiki.

I beg to differ. If people like clicking on stickies, why do people post questions that are already answered in stickies, or make crap posts that reading the stickies would alleviate. In short, they prefer to post rather than read anything.

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

Use fgets() . It clears the buffer and places the data into a char* of your choice. There's the input buffer you have total control over.

vedro-compota commented: +++++ +3
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Put the menu in a function. Call the function anytime you need it.

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

I was about to start working on the other functions but the assignment says I cannot use cstring! Wouldn't it make it much easier if I could?

Then you have to rewrite. char* is cstring

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

Hello Again

in the line 28 ERROR (Expected Array)

why???

Probably because on line 28 you used a command that requires an array and you didn't use one.

Since
1) You didn't use CODE Tags
2) You didn't bother to tell us what line 28 is
we can't very well tell what you did wrong. You'll have to post useful information for our understanding.

hkdani commented: Shows understanding in the basic concepts of Visual Basic programming. And based on experience quickly points out valuable insights. +6
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Second post of the exact same question... Thread closed.

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?
[*]If you have errors, post them! We can't see your screen.  We can't read your mind. You need to tell us what happened.
[*]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. …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

So does this mean people don't like to read the manual anymore or is it that they don't like being told to read the manual.

After decades in the computer industry, I can assure you -- people never liked to read the manual.

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

I'm just waiting to hear the Democridiots. They're a hoot!

As for charging the rich 5% more -- why? Make the tax laws sensible.
Line 1: What did you make?
Line 2: Deductions - few and sensible, not hundreds of pages worth.
Line 3: What's left?
Line 4: Multiply by 20%
Line 5: Send it in.

Everybody does the same form, from $10,000 to $10,000,000,000 income.

Why penalize the rich just because they are worked harder (smarter) than the non-rich?

hkdani commented: Not only is WaltP smart. He has common sense. +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

First of all, it would help for readability to use what are universally accepted variable declarations for variables.

They are far from universal.

Experienced programers used to accepted standards could easily mistake your variables for the wrong type.

No we don't... Standards of this type are company or personal standards, not universal. There are many other standards that don't use str, lng, etc. Any of them are acceptable, some are better than others.

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

Try it without the bastardized *_s functions. Just use fscanf() and fopen() . They are standard and work in all compilers.
Be sure to check the syntax of fopen() because it's different than your use of fopen_s()

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?
[*]If you have errors, post them! We can't see your screen.  We can't read your mind. You need to tell us what happened.
[*]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 …
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

So I changed my code around a little and I think i'm almost there but i'm still getting the wrong counts for some of the categories.

When asking for help, details are needed. What's wrong with the counts?


See the comments:

#include <iostream>
using namespace std;
int main ()
{
	int num = 1, even = 0, odd = 0, positive = 0, negative = 0;

	while (num != 0)
	{
		cout << "Please enter a number (0 to exit): ";
		cin >> num;
		//// What if you entered zero? You still process it...

		if (num %2 == 0)
			even++;
		else if (num %2 != 0)  // Why the IF? the ELSE is guaranteed to be odd
			odd++;
		if (num > 0)
			positive++;
		else if (num < 0)  // Same here, if you don't process the 0
			negative++;
	}
	cout << even << " even numbers"<< endl;
	cout << odd << "  odd numbers"<< endl;
	cout << positive << " positive numbers"<< endl;
	cout << negative << " negative numbers"<< endl;
}

And don't mix TABs and SPACEs with your indents. Change all tabs to 4 spaces in your IDE so your indenting works better.

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

OK then, what was it you needed?

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

Well said, WaltP.

Thanks. Feel free to use it when appropriate...

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

Where did you close the first file before opening the second file with the same FILE variable?

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

You do it exactly as you did -- assuming your description is exactly what you have.

Therefore, give us a complete description of
1) where the data come from that gets loaded into the array
2) your code that loads the array
3) the entire code that looks at the array
And use CODE Tags when posting the code.

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

This isn't what I need, I need to count stars that are written by function and count them (a.k.a. Surface Area). Thanks anyway.

It's exactly what you need. As Clinton shows, increment a counter every time you output a *. I leave you to work out the rest of the details.

Or did you want us to finish your code for you?

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

Here are two things you should learn:

1) Always use good formatting when writing your code. Here is your code formatted nicely:

Actually, his code is formatted better than yours. The only bad thing about his formatting is inside the initial while statement (not indented) and the last cout statements (indented too far). Your indentation is much too deep on every single line of code except the final cout statements.

So how do we code this? Notice that in your else-if chain there would only be one variable incremented per round, because once one variable was incremented then all of the rest of the else-if statements were skipped.

Not true. His "else-if" (properly if-else ) chain was correct. He had 2 IF 's, but your reformatted version was modified to create only 1.

The points about
1) "think through your problem"
2) "your else-if statements are outside of the while loop"
3) "you have the problem of entering zero to end the program"
are correct.

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

Then why did you do it yet again today? That post deleted and infraction given. As Narue said:

Congratulations?

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

Actually i am not getting how this code is working?
Could anyone explain this please????

Then you need to study harder. The code is easy to follow. Use pencil and paper to follow what it's doing -- kinda like in your math class.

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

Create a function called isdelim(char c) that tests c for one of the delimiters.

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

You can't assign an array to an array like that. Use a loop.

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

I've never had a problem with files before, but now I can't seem to get it to work properly.

I have this code:

fstream someFile("file.txt");
    ...

Is the file opened for read, write, append, ???
Did the open return an error?

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

To copy to another location, open the file in binary mode then read/write 255 bytes at a time until end-of-file is reached. Another way to do it on MS-Windows is call win32 api function CopyFile()

I'd use 256. It fits better in the realm of binary. Any power of 2 would work.

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

Nitpick...

First off, the parentheses are missing (sizeof(arraytotal)).

Although most programmers use sizeof(x) , it's perfectly acceptable to say sizeof x .

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

Is counter a single variable or an array?

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

Actually, you should have 2 if-else statements: if even increment evenCount else increment oddCount Same with positive/negative

As for exiting when 0, add one more IF to encompass everything from just after input to bottom of the loop. If != 0, do the stuff

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

Depends on what you mean by interact. Nothing kinky I hope.