• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 244
  • Last Modified:

Problem with simply reading in values, no idea what could be wrong.

Alright, I'm completely beat as to how my program cannot be working. I'm having trouble simply reading in some numbers to use.

After the third scanf, when running the program, the program sort of freezes. The cursor blinks, but nothign can be entered, i can only kill the window.

The program is not complete of course, but it should at least be able to read in the 3 numbers, "reli", "trials", and "seed". I should also be able to get to the system pause.

Here's the code, help me if you can, thanks.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()

int trials, flag, i, c, j, k;
float reli, seri, para, comp, counts, countp, countc;
unsigned int seed;

printf ("Please enter the decimal value of you component reliablility: ");
scanf ("%f", &reli);

printf ("Please enter the number of trials you'd like to perform: ");
scanf ("%f", &trials);

printf ("Please enter the seed value for the random number: ");
scanf ("%u", &seed);


for (i=0; i<=trials; i++)
      for (c=0; c<3; c++)
          seri = ((float) rand()/RAND_MAX);
          if (seri>reli)
      if (flag==1)

      return 0;
  • 2
  • 2
1 Solution
> scanf ("%f", &trials);
The 'trials' variable is an int. Should be 'scanf("%d", &trials)'.
aonuAuthor Commented:
What... a... stupid... mistake...

*shoots self*


PS: Does my srand look ok? The idea is to have a seed set for the random number generator, and I've only gotton vague answers.
The srand() looks fine. Note that the result of the rand() function depends only on the supplied seed and is therefore not random at all. The sequence generated by rand() does have some nice statistical properties though. You can also seed the random number generator using the current time (srand(time(0))) if you simply want the output of the program to be different each time it is run.
aonuAuthor Commented:
Aha, I'll have to keep that in mind, although the program requires some control over the seed, somewhat ironically.

Thanks very much for your help, I hope the rest of my program goes smoothly enough
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

We Need Your Input!

WatchGuard is currently running a beta program for our new macOS Host Sensor for our Threat Detection and Response service. We're looking for more macOS users to help provide insight and feedback to help us make the product even better. Please sign up for our beta program today!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now