Jump to content


Urgent question on C++


  • You cannot reply to this topic
3 replies to this topic

#1 zenlakin

    New Member

  • Members
  • Pip
  • 2 posts

Posted 27 October 2007 - 12:06 AM

I am trying to finish up a simple random generator program and have gotten so far and I am not sure how to finish up the loop. Here is my current code. Current when compiling I am also getting error C2064: term does not evaluate to a function taking one arguments.

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

using namespace std;

void intro();

int main()
{

int lambda, mph, mps, simulations, random, seed;

mps = (lambda/3600);
lambda = mph;

cout << "Volume per hour: " << endl;
//message volume per hour = Lambda.
cin >> lambda;


// number of simulations
cout << "Number of simulations: " << endl;
cin >> simulations;


// random number generator seed.
cout << "Enter a seed: " << endl;
cin >> seed ;
double increment = .5923;
int modulos = 32767;
int multiplier = 2743;
seed=(((int)(multiplier*seed + increment))%modulos);
srand(seed);
random = rand();



//loop
int i;
int interval;
float log;
for (i=0; i<lambda; i++)
{
interval = (-1/lambda)*log(1-random);

cout << interval << endl;
}

return 0;
}

#2 .oisyn

    DevMaster Staff

  • Moderators
  • 1822 posts

Posted 27 October 2007 - 12:21 AM

Please put your code inside [code]...[/code] tags, and specify which error line gives you the error. You can't expect us to compile the code for ourselves.

As for your program, look at the first few lines of main(), and think about what they should do. Remember that the statements are executed in the order as specified.
C++ addict
-
Currently working on: the 3D engine for Tomb Raider.

#3 zenlakin

    New Member

  • Members
  • Pip
  • 2 posts

Posted 27 October 2007 - 12:28 AM

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

using namespace std;

void intro();

int main()
{

        int lambda, mph, mps, simulations, random, seed;

		cout << "Volume per hour: " << endl;
        //message volume per hour = Lambda.
        cin >> mph;
		lambda = mph;
        mps = (lambda/3600);

        // number of simulations
        cout << "Number of simulations: " << endl;
		cin >> simulations;
        

        // random number generator seed.
        cout << "Enter a seed: " << endl;
		cin >> seed ;
        double increment = .5923;
        int modulos = 32767;
        int multiplier = 2743;
        seed=(((int)(multiplier*seed + increment))%modulos);
        srand(seed);
        random = rand();



        //loop
        int i;
        int interval;
		float log;
        for (i=0; i<lambda; i++)
        {
                interval = (-1/lambda)*log(1-random);
				
                cout << interval << endl;
        }

        return 0;
}


Sorry about that. I am getting that error right in my for loop on the line "interval = (-1/lambda)*log(1-random);"

#4 xelohs

    New Member

  • Members
  • Pip
  • 1 posts

Posted 27 October 2007 - 01:26 AM

I see more than 1 problem with the code you pasted.

Quote

seed=(((int)(multiplier*seed + increment))%modulos);

multiplier*seed = an integer
adding an increment less than 1 does nothing here if you're casting it to an int right after.

next... you declare a float called log.
This can't be what you're trying to do.
You can't call the log() function from math.h if you're going to declare a variable called log. Also... log() does not take an integer as a parameter. you can check http://www.cplusplus.../cmath/log.html for reference.

To make it compile you need:
To take out the >>float log; statement
The parameter to log to be a float or double.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users