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

Jencas is correct. You might want to set a flag to stay in the loop (set to TRUE before entering the loop). Then in the loop set up a nested IF:

IF the coordinates are good
{
    IF the location is EMPTY
    {
        set the flag to FALSE so the loop exits.
    }
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

So we're supposed to write your program because you're in chemical engg? Explain this...

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

1) Copy the file
2) close the files
3) Open both files for read
4) read each file byte by byte and make sure both bytes are identical. If not, bad copy.
5) if you hit EOF at the same time, the files are identical
6) close the files
7) output the status if necessary

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

WOW! 4 pieces of code to choose from! Which one works best? Which to choose to turn in as the assignment answer?

C'mon guys, we're here to help, not do everyone's assignments for them!

jephthah commented: word. +4
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

What is the point of the end return? etc etc.

To return from the function, probably. :icon_rolleyes: Just because you don't want to be explicit doesn't mean others shouldn't be. And what etc etc? I don't see that anywhere in the code.

xitrum69, you should really have braces around your loops. They make the code easier to read. It is best to be explicit, which causes fewer errors. And a cut/paste of your code doesn't help others learn. It helps them cheat. But pointing them in the right direction does help.

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

Such a mass of bad suggestions! Arkm's 1st post is a good suggestion for the read, but alas, the suggestion for using feof() is fraught with peril, and his formatting is atrocious (please click the links). And his second post is just wrong.

Salem then reiterates the easiest and most flexible solution.

So look into reading the whole line and create a function that parses the line by looking for SPACEs and do something with the stuff between the SPACEs. That may be what the suggestion for strstr() is for, but since jephthah didn't say, it's not a very helpful suggestion.

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

Or you could just say system("notepad file.ext"); instead of passing arguments to a function that does nothing more than that anyway. Or if you want the command in a string, just use:

string command = "notepad file.ext ";
   ...
   system(command.c_str());
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Probably. Read the sticky posts...

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

You don't need an array at all. Your idea

1) Get the no as input along with the no of digits

2) Separate the digits by collecting remainders of division by 10.

3) Use the digits, perform the function S(X).

is close. All you need for #1 is to get the value.
For number 2 & 3, get one digit by collecting the remainder, perform S(X) on that digit. Repeat until the original number is 0 and you're done.

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

A slightly more direct explanation:

temp = word[i];        // Save the 1st letter
word[i] = word[j];     // put the 2nd letter where the 1st was
word[j] = temp;        // put the 1st letter where the 2nd was

And please learn to format your code. It's much easier for you (and us) to read. Poorly formatted code does tend to make people that could help you just skip your code.

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

First thing I noticed when you opened the save file was

ins.open(savefile, ios::in);

What does ios::in mean? [the question is a hint]

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

Did you miss reading all of the information posted all over this site about CODE tags, like
1) in the Rules you were asked to read when you registered
2) in the text at the top of this forum
3) in the announcement at the top of this forum titled Please use BB Code and Inlinecode tags
4) in the sticky post above titled Read Me: Read This Before Posting
5) and even on the background of the box you actually typed you message in
????

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

Yeah, I know. The concept is still correct. As a matter of fact, the first byte for those keys has been 0xE0 long before XP was created.

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

The 4000+ guests! :icon_mrgreen:

~s.o.s~ commented: :-) +23
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Another lazy attempt at getting help -- with no Code Tags. Why didnt you read any of the requested information posted all over this site about CODE tags, like
1) in the Rules you were asked to read when you registered
2) in the text at the top of this forum
3) in the announcement at the top of this forum titled Please use BB Code and Inlinecode tags
4) in the sticky post above titled Read Me: Read This Before Posting
5) on the background of the box you actually typed you message in

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

I read and throughly understood Aia's post (although he thinks otherwise). My assertion is that the C standard should have included such a practical header as conio.h, and they should have simply selected a good conio.h file, as a part of our C standard. Then the C purists wouldn't have anything to gripe about when they see it in a program.

Every compiler may not have had the same contents or functionality in their conio.h file, but they would fall in line if conio.h was defined in, and made a part of, the C standard, before long.

Then you don't understand the original concept for C/C++. The language was designed to be completely hardware independent. conio.h requires knowledge of the hardware -- specifically a monitor and keyboard. That is the reason it's never been added to The Standard, and never should be. The designers did it that way on purpose, and that's why all the conio.h files are different. They are add-ons by the compiler designers to access the I/O devices they designed their compilers for.

Borland's conio.h, for instance, would have been a good choice, imo.

I agree. I like Borland's header quite well. Unfortunately, it's still non-standard and I will still let people know it's non-standard and should not be used.

But at the same time, I also understand that the suggestion will not be acted upon in many cases because the functions in conio.h may be necessary to write a program with the exact functionality …

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

About kbhit(): look at my program example ...

I did, and don't see why you need a kbhit() for that. A simple test for 0 would work.

... then try to print the second byte of a special key without kbhit() at the same line...

Simple without the kbhit() . Look at my code and make the simple change...

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

My problem is that ...

... you can't be bothered to read any of the requested information posted all over this site about CODE tags, like
1) in the Rules you were asked to read when you registered
2) in the text at the top of this forum
3) in the announcement at the top of this forum titled Please use BB Code and Inlinecode tags
4) in the sticky post above titled Read Me: Read This Before Posting
5) on the background of the box you actually typed you message in

Also do a search about why you shouldn't use void main () . Also, try dropping the ".h" off of your #include statements.

No need to search. Here's a link.

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

Actually, if you need to simply accept input, you don't need kbhit() at all:

c2 = 0;            // reset c2 to 'nothing'
c1 = getch();      // wait for a key
if (c1 == 0)       // check if it's a function key
{
    c2 = getch();  // it is, get the function value
}
//  if c2 is not 0, a function key was pressed

kbhit() is useful when you want the program to continuously run and when a key is pressed do something different. For example:

if (kbhit())        // check to see if a key was pressed
{                   // a key was pressed so we interrupt the standard 
                    //     programming cycle
    c2 = 0;         // reset c2 to 'nothing'
    c1 = getch();
    if (c1 == 0)
    {
        c2 = getch();
    }
    //  if c2 is not 0, a function key was pressed
    ...
}
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

... regarding using conio.h and gotoxy()/Gotoxy(), which are not "undefined" with either the right OS (finally), or the right header files.

Aia is trying to inform you that there is a C/C++ Standard in place. conio.h is not and never has be a C/C++ Standard header, and is only defined in very few compilers. Therefore, use of it and any function defined in it is not portable!

AAMOF, different compilers that have defined conio.h have not implemented the same functions. And sometimes the functions that are defined that have the same name don't even do the same thing.

So, when we 'quote' the Standard it's so the poster can in fact write code that has a chance of being portable. And we will generally gripe about non-standard functions for that very reason. Using your example, with my compiler I get an error using Gotoxy() . And my compiler has conio.h

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

And this series will explain why you should generally avoid scanf()

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

Do you have to read all the posts you already read on a 5 page topic?

Why would you?

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

Is it such a big deal?

Yes. If it wasn't a big deal, why would we mention it in so many places?

If you can't follow simple instructions, you will never be a good programmer -- nor a good anything else.

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

I think I fixed everything now the program end abruptly after the second menu. I've tried a number of things, couldn't get it , I'm not giving up just looking for a slap in the face and a pointer in the right direction. How do you guys stay sane with the frustration of programming?

Well, first thing I do is format the code so it can be followed. Many times that alone will point out the problems.

Next is write small sections at a time, compile, test. Then do another section.

Then add output statements to show you when the program hits key spots and display values that are important.

And the most important sanity measure -- take a break, watch a few minutes of TV, and drink a cola.

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

Now I'm really confused. When I don't include system("PAUSE"); then the console screen just pops up and instantly disappears.

Look here

Or, to keep it on site, look here. :icon_wink:

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

Ahhh, yes. Thanks for the correction, vmanes. I was thinking of another input style. Had a brain fart... :icon_redface:

iamthwee commented: Stick to 'c' mate. -3
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

sms 2 me tht u hv a prblm. snc we no u so well, we sgst cndl mkg. its mch ezr thn cptr

Ezzaral commented: Excellent! +10
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

I'll try to use them (code tags) from now on, didn't know it before, so thanks again

Really? At the top if this forum are the following posts:

  • Read This Before Posting
  • Please use BB Code and Inlinecode tags

Additionally info is listed in The Forum Rules you were asked to read multiple times when you registered. And if that's not enough, they are also explained on the background of the box you posted all your messages in. What else could we have done to help you?

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

There no any reason on why do we have to convert it binary to hex. At at least i havn;t come across any application which need a that feature!

I have.

mitrmkar commented: same here ... +4
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Implicit type casts works (as usual in C) in strange inpredictable manner.

Since inpredictable is not a word, I assume you mean unpredictable. The problem with this statement is that casts are completely predictable.

Can you give us an example that is strange and unpredictable?

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

Second problem is you are forgetting that the RETURN you type in is also a character that gets put into the buffer. Therefore, in this code:

cout << " Empezar?? " << "\n";         // TO START
	cout << "    1 - SI" << "\n";
	cout << "    0 - NO" << "\n";
	cin >> empezar;
	cout << "\n" << "\n";

	while (empezar != '0')      // IF I PUT THIS WITH '' DOESNT WORK. IF DONT, DOESNT TAKE IT
	{
		cout << " Ingrese lo que va a enviar: " << "\n";
		cout << "    3 - Carta" << "\n";
		cout << "    4 - Paquete " << "\n";
		cin >> a_enviar;
		cout << "\n" << "\n";

if you enter 0, empezar gets the value '0'
if you enter 1, empezar gets the value '1' and a_enviar reads the RETURN.
if you enter only RETURN, empezar reads the RETURN and since it's not '0' the loop is started.

Salem commented: Yep, good old character based input strikes again. +20
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

So here's what I have so far, I know it's not correct but I think im on the right path, can someone let me know whats wrong...

Actually, it's your job to tell us what's wrong, not let us try to figure out what the program is doing and what we think is wrong...

Please, start IDE, open your project, click on rand() call in the source then press sacramental key F1. Read about returned value range (RAND_MAX macros) then take a piece of paper and a pencil and perform a simple calculations: how to get a numbers from 1 to 6...

Maybe you need to explain what's wrong with his calculation. Seems to be fine to me.

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

Or offer the option to turn that feature off in one's control panel. I personally would use it because I always preview before posting anyway.

As do I. Except when you see I edited a post... :icon_rolleyes:

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

Where are you having the problem?
What does the program do wrong?
What makes it wrong?
What should it do instead?

When asking for help it's necessary to explain the problem, not just toss 3 ambiguous sentences together without punctuation making it hard to decipher your meaning.

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

Don't waste the time, you live in C World now:

++array[indexNum];

I've always preferred the post-inc format array[indexNum]++; for some reason. It's programmer's choice since they both ultimately do the same thing.

And just for completeness, you can also do array[indexNum ] += 1; Not extremely useful for increments of 1, but great if you need to add other than one (integer and floating)

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

I like that option. The VEdit forum does the same thing.

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

Paolo,
Have you successfully used this process before and it's just this program that doesn't work? If so, I'm not sure what's happening. If not, as a guess, TC2 is compiling the program in a form that cannot be converted into a .COM file. There are (were?) restrictions that make most .EXE files not .COM compatible.

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

I have a string of the form "abcd\"1234\"efgh". I want to extract 1234 from this string. How should I do this?

That depends on if you need to
1) find 1234 in the string and extract it
2) find the two "s and extract what's between them
3) extract the 5th through 8th characters.

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

The program you're writing will work on ANY C compiler, even piece of crap compilers, which Turbo C is not one of. It pisses me off every time someone denegrates good compilers just because they are older. If they do exactly what the user needs, it's fine. It just can't do advanced 32bit stuff that the user obviously doesn't need. It still is C. It still works fine. And TC can still do things none of the current compilers can do.

I agree upgrading should be considered, but is not necessary. And definitely TC should not be put down.

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

Look into findfirstfile and findnextfile .

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

You cannot compare character strings in this manner. You need to use one of the string functions.

You probably want if ( strcmp(argv[1], "e") == 0 )

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

It would be best to let us know what O/S and compiler you are using so we don't have to guess, as jephthah was forced to do. They all have different ways to accomplish the task.

jephthah commented: yup. i was just having a momentary bout of niceness :P +3
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

It seems this question -- exactly -- has been posted already.

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

You also need to format your code so we can read it.

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

ICODE is not meant for multiple lines of code. That's what CODE tags are for.
Extra whitespace on a single line of code may or may not be useful. I probably agree that ICODE should retain whitespace, but not EOLs.

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

yeah, to be fair, zips have been common since windows 3.1

Long before that, even.

So what would you suggest, Midi so 100% of the people can use the files? Instead of only 99%... :icon_rolleyes:

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

Gee. IE -- strike one. Vista -- strike two. Only need one minor thing to go wrong and -- strike three. You're OUT! :icon_wink:

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

Actually, no you didn't...

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

get rid of the long type cast. that's what's hurting you here. Furthermore, since you've already defined everything as a double anyhow, you have no need to do any type casting at all. they already are doubles. this is all you need to do to get your answer:

beloeb = (antal_minutter * minuttakst * 10000.0 + 0.5) / 10000.0

.

How does adding .5 to a double round the value? It simply adds .5 to the value. To round you must drop all digits beyond the needed digit. Using your technique, you need:

beloeb = long((antal_minutter * minuttakst * 10000.0) + 0.5) / 10000.0;

Casting to long to truncate after the addition.

also, you don't need to use the format specifier "%lf" to print a double. "%f" is the correct format specifier. actually i'm not even sure if "lf" means anything.

Yes he does, and yes it does. %f is for float values. A double is a long float, or double the storage space of a float. Therefore, %f is for a single precision floating value, or a float, whereas %lf is for a double precision float, or a double.