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

I had been thinking along those lines, but probably way off with...

if ( choice != "y","Y")

Yes, you're off. You have to test each character individually. Something along the lines of if ((n < 5) || (n == 10)) which is TRUE if n is 4 or less OR equal to 10

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

Or add output statements to display values as the program runs with the location within the program.

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

Is there anyway to do this without using rewind? We haven't learned this yet.

Just close and open the file again.

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

Hi,

I was hoping someone could shed some light on this for me. I am stuck on an assignment. I have spent 3 weeks on it and have almost finished it. I have so much going through my head at the moment I just need some help. Please. I do not expect you to do it all for me!! I have got this far on my own, I just need a little advice and a little help, as I really dont understand it and am having alot of trouble getting my head around it.

---------------
My main problems are that I cannot work out how to display them on the same line as well as do not know a formula of how to work out the ratio.

It took 3 weeks just to print out the fibb series? I would've asked for help after the second day for something that simple.

Assuming it'll take you 3 more weeks before asking your instructor, the ratio is the current number divided by the previous number.

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

I'm with Aia on this topic. Although compilers treat \0 and 0 the same, they are not, since one is a character and the other is an integer. It has to do with human perception, not compiler equivalences.

It's the same as teaching children to dial nine-eleven in case of emergency. Many can't find the 11 button and don't have the knowledge how to correct it.

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

so i cant actually return a number like in C or C++? in other words, the RETURN statement in my get_fore and get_back subroutines is incorrect/illegal? so i guess i will have to put these values in registers before i do the return statement, right?

it seems to me then, that nothing is actually returned in terms of data that the subroutine computed. is that an accurate statement?

No. As AD said, the return value is in AX. So whatever is in AX is returned.

so now am i returning values correcntly? thanks. also if anybody has a burning desire to run my code and check it out feel free! :icon_cheesygrin:

Nope. See above.

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

First, get rid of the clear screen stuff since you cannot make it portable and is not part of standard C++
Second, get rid of the GOTO statement and use a while loop instead
Third, you say you want the "second out put replaces the first" so change your output statement to cout << h << ":" << m << ":" << s '\r' <<ends; \r will move the cursor to the beginning of the line just output.
ends is the same as endl except it does not go to the next line. It basically just forces the output to the screen.

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

We're not going to do your homework for you. You need to show us what you did and we can help you fix it.

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

A stack makes sense. That way you'd be able to catch problems like This is a <I><B>mismatched tag pair</I></B> too.

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

#1) Learn to format your code so it's readable
#2) Isn't y a single character? What's the proper printf() format specifier for a character?

That should help.

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

You cannot compare strings with the == operator. Look up the function strcmp()

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

Since we don't know what the desired output is nor what the program is supposed to do, what can we tell you?

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

Alt-PrtSc to copy the active window to the clipboard
Ctrl-V to paste it into Paint.

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

You're talking about command line parameters. Narue is correct. You can check out this information on how to use the command line.

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

Walt, have you even worked in an assembly plant environment???

I'm a line support engineer at a major facility that employs about 1000 semi-skilled assemblers and electronic technicians, and there is just NO WAY we can maintain assembly lines in a regulated environment using even Win 98, much less DOS.

I've worked in many arenas. From manufacturing and production to medical devices to POS/inventory systems. And as a software engineer, so I know something about programming and systems. Possibly more than a support engineer. Why?

I only took exception to the statement "you just can not physically maintain an assembly line running dos." You like to make blanket statements that are true in your arena, but may not be true outside of your personal experience.

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

Entirely your choice, but I would use a while loop. I would also use recursion (i.e. your function should call itself within the loop), as you'll need to print out the columns in reverse order to how they're calculated.

I wouldn't. I'd just write the loop properly.

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

Oh, yeah, I'll be the first to admit, Turbo C is preferable. but it costs $$.

My ghod! Go to the f'n links and download the FREE Turbo C Compilers I linked to!!!

Stop posting crap -- check your facts!

you just can not physically maintain an assembly line running dos.

Maybe you can't, but it's obvious others have the knowledge to keep older O/S's running. They seem to be doing it.

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

http://www.digitalmars.com/

you have my sympathy.

Why would you even bother mentioning a piece of dreck like that? :icon_rolleyes:

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

The problem's in your code; without seeing your code it's a bit hard to see where the problem is...

No it's not. Almost every error is ... error C2664: 'carddeck' : cannot convert parameter 1 from 'int' to 'int []' You are passing an integer in parameter 1 of carddeck and the function wants an integer array. Read the errors and look at the lines specified. Then look at the variable types and find the mismatch.

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

Use one of these compilers:
Turbo 1.01
Turbo 2.01
Turbo 3.0

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

Copy the file where ever you want, as jephthah suggests.
In the code, use the full path to the file.

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

what about lithp?

Not as old as ForTrash, and definitely not a universal language.

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

I want to know a small c code to generate random numbers.It could be within a certain range.
I want to know if rand() function will generate a random number

Yes, rand() will generate a random number. Also, look up the srand() function which you will also need.

Then search these forums -- there's lots of code showing how to use random numbers.

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

Brittany, you can't do cin >> number..That will not read a value and store it in the array...Do something like this: ...Remember to add to my reputation!

That is exactly how to read in a value into the array. Don't know where you get the idea it can't.

//Find the average
	average = ( numbers[TOTAL_NUMBERS] + numbers[TOTAL_NUMBERS]) /10;

Since when is adding two numbers together then dividing by 10 giving an average?

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

So if I write:

No estimate(data, n, m, &xms,d); data, n, m, d have no value for (i=0;i<m;i++) m has no value printf("\n%f, d[i]"); Improper syntax. Try printf("\n%f", d[i]); instead.

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

Yes, as Traicey implied, learn to format your code. Most of the errors you would have found without asking. F:\C ++ Numerical Methods\Newton_Raphson.cpp(183) : error C2043: illegal break -- a break must be within a loop or switch F:\C ++ Numerical Methods\Newton_Raphson.cpp(184) : warning C4508: 'main' : function should return a value; 'void' return type assumed main() is an int function -- see this -- and must return a value.

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

im building a telephone directory. and the code is given below.
i am using file system to store the record which i get from the user. and then i should be able to do searching, deleting, sorting and other default telephone dir functions. so far i have been able to get the input from the user and store it in a file, retrive the records from the file into a binary search tree and display the contents of the binary search tree.

there are some bugs in this program. bugs i guess are in the building the tree and displaying the tree. i would also like to display the menu after i call the inorder function which i tried but in vain.

If you don't know, how can we help you? We didn't write the program, you did.

//edit: i fixed how to display menu after the inorder function. :)
//the bug is.. wen i try to display from the tree, some records are displayed twice.

i used diffrent compilers (g++, bcc32, visual c++, turbo c++) and i got different outputs.
can anyone suggest a ansi standard compiler.

All of the above. If you are really getting different output, you have some major problems in your code. Narrow down what the problem is and we can help you fix it.

i am not sure if my code is an optimized one. using a binary tree a good idea? or sud i try to do direct …

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

Old? What does that make ForTran??? :icon_twisted:

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

I'd use 4 spaces instead of TABs. Too much indentation is just as bad as none. But that's my personal preference.

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

THE ULTIMATE SOLUTION IS THIS

Only if you can't program... :icon_rolleyes:

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

Read the error
Look at the line in question
Look at the variable types
Correct the problem

It's extremely obvious if you just look at it. Took me all of 2 seconds and I didn't even write the program.

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

the first number .. ok.. i see.. i thought it would move to the next number the next time i open the file... but i'm guessing it will only move to the next number while the file is open and if I close it, then it starts over...

Exactly.

so then how do i get it to define my variables in a way that i can get a loop working...

It's already defined.

i mean do i have to create a month 1, day1, month2, day2.. kind of scheme or is there a way to get it to re-input the variables with the next number every time the loop runs? i'm really lost here.

Maybe you need to step back and write a test program that ONLY reads the file and outputs the data read. Should only take a few minutes and it will explain a lot (I hope).

Key point in programming:
If you have a task and there are 3 things you don't quite understand, don't write the program in one shot. Write 3 programs one at a time exploring each of the things you don't understand. Only when you understand each separately, put them together to solve the whole task.

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

then do i need to close the file outside of the loop where i define x and then open the file inside of the loop to define month and day?

No. You need to think about what opening and closing a file means. When you open a file what's the first thing to be read?

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

tried that and still getting some errors.....

c:\documents and settings\don & diane kruep\desktop\project 04\p04.cpp(28) : error C2664: 'Get_Name_and_Num_Classes' : cannot convert parameter 1 from 'int' to 'std::string &'
1>

The function Get_Name_and_Num_Classes has the first parameter defined as a string, you are passing an int instead.

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

Let's look at your program.

Open input file
Start a loop up to 20 times
    input from the file
    close input file
    process input
end of loop

So, since the input file is closed the second time through the loop, your input causes an error which you never test for. Then you just blindly process whatever is in the input variables (which is the values from the first and only valid input)

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

What are you trying to accomplish with this statement? if (month=12, month<=3)

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

You need to make a decision on how to input a move. Once you make that decision, make another function to accept moves.

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

No, you do NOT want to use getch() . It is a non-standard function and very few compilers have it defined.

The character you need to compare your value to is '\n'. That's as much help as I can give since you won't show us what you did and therefore can't tell what is wrong with how you did it.

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

In order to input the data, you must open the file first. Then you need to read each record and load your structure. Maybe you should read the entire file when you start the program and just keep all the records in memory so you have access to them at all times.

Also, you need to read this to fix a bug.

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

So you get that far and quit? And we get to finish it for you, and we have no idea what's not working? Somehow I don't think I need an A that bad.

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

When you press ENTER all by itself, where does it go? What does it look like?

That's what you put in place of ???.

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

If you don't believe me, then what can I say except for you to read your textbook about pointers. One of our members WaltP has a very good signature
or something like that.

It's actually Salem:

If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.

Ancient Dragon commented: Thanks for the correction :) +25
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Creating a unified rating system does make sense, but it would take awhile to code, so is more likely something a month or so down the line. There are a couple of things that I want to accomplish first, such as adding a 'Flag Bad Post' link to the blogs and code snippets.

But is it something that needs to be done? I'd recommend getting other input as to whether the time should be put into this. I'm not convinced.

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

Hey did anyone ever reply to you?

Can't you tell by the posts in this thread?

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

could any 1 tell me why this code isnt working right??
two.txt is not wriiten good...

Because it's written poorly?

It's your job to tell us
1) what the program is supposed to do
2) what exactly goes wrong
3) why it's wrong
4) what is supposed to happen instead

I assume you haven't read Read Me: Read This Before Posting yet...

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

What you need, in addition to learning how to use CODE tags, is two loops. Loop 1 is for each game. Inside that loop is loop 2 for each guess. You are using one loop for guessing and winning which is very difficult to handle.

The first thing in the outer loop is calculating the number to guess.
The inner loop exits only when the number is guessed.
Then the question about playing again is the last thing in the outer loop.

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

Didn't know adding an icon had the same problem, esp since you added it on the other input box. OK.

Seems to be somewhat of a hacked system if you ask me...

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

BTW: this program is written in pure C and may be better located on the C board than the C++ board.

It was. He spammed the forums with this problem

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

You need to un-nest your if statements. You need to rethink your code some. What you need to do is take each individual process (input, calculation, output, etc) as individual steps. What you have is each step integrated (merged) into the previous step. Separate them into input, calculation, output, and so on. You will be able to expand the program easier.

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

Dani, could you please add ICODE to the quick reply, too? I answer many questions in the QR box and would like to format there, before previewing the message. Then we don't have to run around highlighting all the ICODE pieces and maybe miss one.