#urgent help needed c program

1 messages · Page 1 of 1 (latest)

next whaleBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

wanton dagger
#

what's your question?

final pewter
#

i need help to solve the cpu.c task

#

I just can't get it to calculate the value for SPIN_1SEC and then run the program with it

wanton dagger
#

nobody is going to do the assignment for you

#

if you need help, ask a question that can be answered

final pewter
#

i posted the part i already tried

#

maybe someone can have a look at it and help me

wanton dagger
#

what do you need help with?

final pewter
#

with this

wanton dagger
#

are there any errors? does the output not match what you expect?

final pewter
wanton dagger
#

being vague only makes it harder to help you

#

!howto ask

next whaleBOT
# wanton dagger !howto ask
How to Ask A Programming Question

Anyone can ask a question in our programming channels. Following the guide Writing The Perfect Question is recommended.

What To Post

State your problem clearly and provide all necessary details:

  • the relevant portion of your code, or all of it
  • the expected output
  • the actual output (or the full error) 🏆 Gold Standard: Minimal Reproducible Example
Where To Post

Provide the relevant code in the message, and format it nicely with a code block*. If it's too much for one message, you can upload it:

  • Compiler Explorer for most C/C++ snippets
  • OnlineGDB for interaction, debugging ⛔ Do not post screenshots, let alone photos of your screen!
final pewter
#

I can't get the SPIN_1SEC value right

#

The cpu is used for 1 sec and this time is measured in nanoseconds, I don't know how to calculate and save this value.

woeful pawn
#

SPIN_1SEC describes how often your computer can increment the i variable within a second.
After 1 second has passed you inspect the value of i. You then repeat this a few times and take the average.

If you do not know how to precisely stop time - cause I sure as hell don't - then my approach would be to bruteforce the number.
I would bruteforce it via binary search over all integers (if unsigned int isn't sufficient then of all integers up to 1 << 40 or smth like that). If for a tested number of iterations the computer needs less than 1 second then you look at the bigger half and if it takes more than a second than you look at the lower half.

next whaleBOT
#

This question is being automatically marked as stale.
If your question has been answered, run !solved.
If your question is not answered feel free to bump the post or re-ask.
Take a look at !howto ask for tips on improving your question.