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

whats wrong in my codes

1) main() is an INT function
2) defineing printf and scanf makes the code difficult to follow and is unnecessarily confusing
3) As pyTony mentions, you need to format your code properly.
4) Use a standard function (getchar()) instead of the nonstandard getch().

That's what I see.

Also, when asking for help, details are important. "Wrong Answer" tells us nothing. What did you get and what did you expect based on what input was used?

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

1.warning at line 16 return type of main is not int

Take one guess.

2.error at line 18 syntax before "printf"

Look at the line before printf. What's missing?

ok waltp why cant we nest structures????

Ask the people that designed the language. I never cared why. They said you can't so I don't.

And do what deceptikon suggests. Answering all these basic questions gets tiresome when all you have to do is study the material in your book.

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

The only way to not get decimals is to use fractions. The only way to get only fractions is to not use sqrt() functions and no division.

The only way to get a square root without sqrt() AFAIK is to write a function to calculate the sqrt using an algorithm and stop as you get to the decimal portion. You shold not convert what's left into a fraction.

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

Copy and paste the errors, don't post a screenshot.

Explain the problem -- don't make us try to figure it out.

You cannot nest structures.

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

See my first post.

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

For example, instead of writing a polynomial as follows:

a0*x^0 + a1*x^1 + a2*x^2 + a3*x^3 + . . .

it would have been nice to write it with the proper subscripts and superscripts. I tried to use HTML code (<sub> and <sup>), but that didn't work. Am I overlooking something?

Probably that what you wrote above is understandable and easier to write than using special commands to super- and subscript.

No, I don't think you're overlooking anything.

a0x^0 + a1x^1 + a2x^2 + a3x^3 + . . . Normal

a0*x^0 + a1*x^1 + a2*x^2 + a3*x^3 + . . . Inline Tags

a0*x^0 + a1*x^1 + a2*x^2 + a3*x^3 + . . .  Code Tags

I see what you mean. Use Inline Tags since it is essentially code

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

Point number 4: I was under impression that once a new memory is allocated to my code, that pointer would be pointing to some random data present at that location at that time.I did not knew that realloc already does the 'createACopy' task for me.

New memory, yes, reallocated memory, no. It really does help to understand the functions you are using. Read before using so you know what you're doing.

One more thing. I am new here. I would be trying to answer questions by others. But please cover me if I am giving incorrect informatiom.

Be sure you test before answering. This includes testing code and verifying your information before responding.

It would really help if the person asking the question does a little checking first, but that rarely happens.

teachMyself commented: Sure Thing. +0
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

In addition to what The Dragon said:

1) Never use conio.h and getch() if at all possible. They are non-standard and are only defined in a couple compilers. Use a standard input function. In your case I understand why you used it, but in general, avoid getch()

2) Line up your comments as much as possible:

if (userInput == NULL)                //if malloc could not find sufficient memory
{
    free (userInput);                 //free the memory
    puts ("Error Allocating memory"); //print error message
    exit (1);                         //exit the program
}

3) Make your comments useful:

free (storeOldInputHere); //free the storeOldInputHere
inputLength ++; //increment the length counter by 1

Both comments are worthless. Good comments explain why the statement was used, not what the statement does.

4) realloc() does not loose the contents of the memory so the createACopy function is not necessary. See this

5) using exit(1) from the mainline is not necessary. return(1) will suffice. exit() is used when you are deep inside functions and must exit when returning with and error code is not an option.

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

If your sort key is short, you can loop to
1a) remember line position (ftell)
1b) read line
1c) extract the key
put both key & position in a structure array
Now sort the structure
Read each line from the the line position (fseek) and write the sorted file.

I used this technique and it was quite fast, even with reading the file twice.

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

It's unlikely that sqrt(bb-4a*c) will be an integer (or even a rational number).

Oh yeah?

int sqt;
sqt = sqrt(b*b-4*a*c);
print sqt;

Looks integer to me...

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

Arrays maybe?

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

Your answers are in integers. Integers don't have decimals.

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

So what does it do wrong? To get help you need to post details, not just a vague "it doesn't work" message. We need to know how it fails in order to understand what "doesn't work" means.

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

Because it won't work the way you have it. You cannot end the format string with \n.

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

Try printing out avarything you read in as soon as you read it.
Can you use STRINGs rather than CHARs? If not, make your CHAR array larger -- say [20].

...oh my,

Channelling George Takai, I see... ;-)

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

So pick a better compiler

WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
i++,++j;
k = i>j? i: j;

That's not your macro. The macro is only 1 line.
Try it again.

Study the definition of a magro again.

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

Try it and find out! You'll get the answer in seconds!

I fear for the future

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

Why should it be?

Remove MAX and put the macro code directly in your code and see what happens.

Post the results.

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

I still don't see a question. All we can do with the info you gave us is write it for you. That's not how we work here. What problems are you having? What have you tried? What don't you understand?

And, just so you know, your professor is 30 years out of touch with programming. He's forcing you to use the equivalent of spears when the rest of the world uses lasers. He's teaching you something you'll never use in the real world.

i just need a super simple and basic codes :) thanks

Ahh, I see. You do want us to write it for you. Sorry, not going to happen. We don't get the grade and you won't deserve it. And what would your professor say when he finds out?

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

Probably because you are reading into a pointer but there is no storage space so you are overwriting some unknown memory you shouldn't be touching.

When asking for help, be sure to give better detail. There are hundreds of "runtime errors". Which one? And what statement?

And don't use anything in conio.h. You'll be sorry when you move on to a real compiler and your functions no longer work.

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

Yes, we can help. Ask a question...

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

Passe. When you can get an anwser in hours by posting a question and spending no effort, why spend the energy to open the manual and get the answer in seconds?

I_m_rude commented: a BIG LOL +2
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

Since you barely know C++, is it a good idea to start another language and leave C++? Why waste the last 7 months? Develop your skills.

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

((-b) + sqrt(bb-4ac)) / (2a)

See that /? Don't do that. Assign numerator and denominator to separate variables and print them out.

num = ((-b) + sqrt(b*b-4*a*c))
den = (2*a)
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague

getch() blindly gets a character.
getche() echos the character.

Both of which you would have been able to answer in seconds by trying them.

But, avoid using them because they are not standard and are only supported in a couple compilers.

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

what you mean by that?!

"It might help to explain what you don't understand."

Might = possibility exists
Help = to aid; to give a clue
Explain = give details; expand your explanation to include more information
Don't Understand = your confusion area; what confuses you

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

Looks straight forward to me. It might help to explain what you don't understand.

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

How do you "generate four random numbers from the array"?
refer to first post

Telling me to re-read the post I quoted does NOT answer the question. I'm asking because your first post says this and I don't understand it.

what's in the array?
random numbers

So it's just crap in the array from uninitialize data and you have no idea what the values are. Got it.

What about the 7x4 array?

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

My guess is the problem wants you to create your own BigInteger program, not use a ready-made library. What do you actually learn by using someone else's code?

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

Lucky you... It must be your signature 'cuz IT Consultant usually makes grls run away! ;-)

Just report the spammer (as you did) and they will be banned.

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

sepp2k explained it.

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

I am so lost on what to do so please help how ever you can.
I must write a program to calculate the cost and time it takes to fill a swimming pool.

Take each step and program it. Start with:

  • Inputs:
    Length, Width, and Depth of the pool

Write this sections, test it. When it works, move on to

Calculation functions:

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

Given a 7x4 array generate four random numbers from the array with no repetition.

Your code and your description don't match at all. Where is your 7x4 array?
How do you "generate four random numbers from the array"? what's in the array?

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

IOW, get rid of the \n in the scanf() call.

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

if(user=="abel" && pass=="pass")

Look up how to compare strings again. You need to use strcmp()

And remove your 2 #define's. They make the code harder to understand, not easier.

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

Completely disagree. After only 1 week, you don't have the background in the language to even think about graphics yet. Learn the language first. Graphics can come later.

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

No, design, as in plan.

If you are going to make a car, do you just throw metal together and hope it works? No, you design the car. When the design is finished, you then build the car based on the design. Same with a program.

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

Format your code.

Explain what? You didn't tell us anything we can explain.

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

All fixed! Thanks.

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

I don't see why (nor how) semaphores would be used in this problem. My solution would have a 4-integer array representing the lanes which contains the number of customers in it. A loop looks at the values and finds the minimum value. That's your chosen lane.

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

Yes, it says Private Messages (1) at this time.
"You don't have any received private messages."
"You don't have any sent private messages."

I know it should reset to 0, but it didn't.

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

You don't. You parse a file by reading it and breaking the line read into fields. Then you can store it in your structure.

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

No, this is a help board -- not a teaching system. You'll have to do a lot of research on robot and firmware programming.

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

It's difficult. You have to understand how to design, store, and retrieve data from a database you design.

I'd go with something like craps, tic-tac-toe, mastermind (also somewhat complex). A game that remembers a little bit of information but not too much.

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

Tell them they are wrong and do some research before giving people wrong information again.

Tell them to read this thread, and the C standard.

And don't blindly believe the experts. Sometimes even they make mistakes, or have been mislead themselves. Search for your own information and verify what you are being told.

[EDIT]
Ahh, I answered the wrong question. Yes, tell them it is undefined and you cannot tell for certain what the value will be. It may change depending on the compiler.
[/EDIT]

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

Can someone (Dani?) please reset my PM count to zero since I have no messages and its claiming I have 1?

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

Companies always ask these tricky-defination type questions.

They do? How many job interviews have you been on?

Paraphrasing for ease of understanding:
An expression is that portion of a statement that has operators (*+-<> etc).
A statement ends in ;

There's more to it but that's what you can grasp at this moment.

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

They are incorrect. Anything that is "compiler dependent" should be avoided.

As deceptikon said, it's undefined. Listen to experts, not friends.

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

Like it's on fire. Covered with ants. Ants on fire.

Roasted ants! Yummm!!!!