• C

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);

srand(seed);

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


      system("PAUSE");
      return 0;
}
aonuAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mtmikeCommented:
> scanf ("%f", &trials);
The 'trials' variable is an int. Should be 'scanf("%d", &trials)'.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aonuAuthor Commented:
What... a... stupid... mistake...

*shoots self*

thanks.

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.
0
mtmikeCommented:
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.
0
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.