?
Solved

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

Posted on 2003-10-31
4
Medium Priority
?
238 Views
Last Modified: 2010-04-15
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;
}
0
Comment
Question by:aonu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
mtmike earned 500 total points
ID: 9660105
> scanf ("%f", &trials);
The 'trials' variable is an int. Should be 'scanf("%d", &trials)'.
0
 

Author Comment

by:aonu
ID: 9660406
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
 
LVL 5

Expert Comment

by:mtmike
ID: 9660489
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
 

Author Comment

by:aonu
ID: 9660570
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question