Help please!!

anybody to hepl me to run this program?? i can not fix it

/*
mm1.cpp
*/
#include
#include
#include
#include
using namespace std;
const CN_TSIM = 5000;
const CN_HOW_MANY_VALUES = 20;
const double CN_MIDDLE_RAND = CN_TSIM *2.4/
CN_HOW_MANY_VALUES;
const CN_LL = 8;
const CN_MM = 12;
const CN_MI =( CN_LL + CN_MM);
const double CN_PP = 1.0 * CN_LL / CN_MM;
int expo( double &u) {
double
e( rand()+ 1);
int
i( 0);
e /=( RAND_MAX+ 1);
e = exp( -e);
u = 1 - e;
e = - log( u) / CN_MI;
i =( int)( e * CN_MIDDLE_RAND);
return i;
}
int main() {
const double P_ip1 =( double) CN_LL / ( CN_LL + CN_MM);
int
x( 0),
t( 0),
i( 0),
j( 0),
cust_in( 0),
cust_out( 0),
W[ 1+ CN_HOW_MANY_VALUES],hm[ 1+ CN_HOW_MANY_VALUES];
double
U( 0.0),
mpps( 0.0),
P[ 1+ CN_HOW_MANY_VALUES];
cout << "M/M/1" << endl << "------" << endl << endl;
srand(( unsigned) time( NULL));
for( int k = 0; k <= CN_HOW_MANY_VALUES; k++)
P[ k] = hm[ k] = W[ k] = 0;
i = 1;
while( true) {
// compute 'x'
x = expo( U);
if(( t+ x) > CN_TSIM) {
W[ i] += ( CN_TSIM- t);
break;
}
W[ i] += x;
t += x;
hm[ i]++;
// compute 'j'
if( U < P_ip1) {
if( i > 0) {
i = j = i - 1;
cust_out++;
}
} else {
if( i < CN_HOW_MANY_VALUES) {
i = j = i + 1;
cust_in++;
}
}
}
for( int m = 1; m <= CN_HOW_MANY_VALUES; m++)
P[ m] =( double) W[ m] / CN_TSIM;
for( int n = 0; n <= CN_HOW_MANY_VALUES; n++) {
cout << "W[";
cout.width( 3);
cout << n << "]= ";cout.width( 4);
cout << W[ n] << ", P[";
cout.width( 3);
cout << n << "]= ";
cout.width( 5);
cout.setf( ios::fixed);
cout.setf( ios::showpoint);
cout.precision( 2);
cout << P[ n]*1e2 << " %, Afikseis: ";
cout.width( 3);
cout << hm[ n] << endl;
}
cout << endl;
return 0;
}

thanks

Comments

  • : anybody to hepl me to run this program?? i can not fix it

    I see why you cannot fix it. You can't even _read_ it! Get your layout right. Fix the warnings your compiler will emit. #include the standard C++ header files (cstdlib, cstdlib, cmath) all without the '.h'. Give your variables names readable names. Add comments better then 'compute x'. Use asserts.

    If your program compiles cleanly, but you still have problems, use the code tags, [leftbr]ode] and [leftbr]/code], and post the code.

    Good luck,

    bilderbikkel
  • : : anybody to hepl me to run this program?? i can not fix it
    :
    : I see why you cannot fix it. You can't even _read_ it! Get your
    : layout right. Fix the warnings your compiler will emit. #include the
    : standard C++ header files (cstdlib, cstdlib, cmath) all without the
    : '.h'. Give your variables names readable names. Add comments better
    : then 'compute x'. Use asserts.
    :
    : If your program compiles cleanly, but you still have problems, use
    : the code tags, [leftbr]ode] and [leftbr]/code], and post the code.
    :
    : Good luck,
    :
    : bilderbikkel

    I make the changes for the headers..Now the programm running but only for 0,5 second and close..i can't see it..Any ideas please?

    Here is the new running programm:

    /*
    mm1.cpp
    */
    #include
    #include
    #include
    #include

    const CN_TSIM = 5000;
    const CN_HOW_MANY_VALUES = 20;
    const double CN_MIDDLE_RAND = CN_TSIM *2.4/
    CN_HOW_MANY_VALUES;
    const CN_LL = 8;
    const CN_MM = 12;
    const CN_MI =( CN_LL + CN_MM);
    const double CN_PP = 1.0 * CN_LL / CN_MM;

    int expo( double &u)
    {
    double
    e( rand()+ 1);
    int
    i( 0);
    e /=( RAND_MAX+ 1);
    e = exp( -e);
    u = 1 - e;
    e = - log( u) / CN_MI;
    i =( int)( e * CN_MIDDLE_RAND);
    return i;
    }

    int main() {
    const double P_ip1 =( double) CN_LL / ( CN_LL + CN_MM);
    int
    x( 0),
    t( 0),
    i( 0),
    j( 0),
    cust_in( 0),
    cust_out( 0),
    W[ 1+ CN_HOW_MANY_VALUES],hm[ 1+ CN_HOW_MANY_VALUES];
    double
    U( 0.0),
    mpps( 0.0),
    P[ 1+ CN_HOW_MANY_VALUES];
    cout << "M/M/1" << endl << "------" << endl << endl;
    srand(( unsigned) time( NULL));

    for( int k = 0; k <= CN_HOW_MANY_VALUES; k++)
    P[ k] = hm[ k] = W[ k] = 0;
    i = 1;
    while( true)
    { // compute 'x'
    x = expo( U);
    if(( t+ x) > CN_TSIM) {
    W[ i] += ( CN_TSIM- t);
    break;
    }

    W[ i] += x;
    t += x;
    hm[ i]++;
    // compute 'j'
    if( U < P_ip1) {
    if( i > 0) {
    i = j = i - 1;
    cust_out++;
    }
    }

    else {
    if( i < CN_HOW_MANY_VALUES) {
    i = j = i + 1;
    cust_in++;
    }
    }
    }

    for( int m = 1; m <= CN_HOW_MANY_VALUES; m++)
    P[ m] =( double) W[ m] / CN_TSIM;
    for( int n = 0; n <= CN_HOW_MANY_VALUES; n++) {
    cout << "W[";
    cout.width( 3);
    cout << n << "]= ";cout.width( 4);
    cout << W[ n] << ", P[";
    cout.width( 3);
    cout << n << "]= ";
    cout.width( 5);
    cout.setf( ios::fixed);
    cout.setf( ios::showpoint);
    cout.precision( 2);
    cout << P[ n]*1e2 << " %, Afikseis: ";
    cout.width( 3);
    cout << hm[ n] << endl;
    }

    cout << endl;
    return 0;
    }

  • : : : anybody to hepl me to run this program?? i can not fix it
    : :
    : : I see why you cannot fix it. You can't even _read_ it! Get your
    : : layout right. Fix the warnings your compiler will emit. #include the
    : : standard C++ header files (cstdlib, cstdlib, cmath) all without the
    : : '.h'. Give your variables names readable names. Add comments better
    : : then 'compute x'. Use asserts.
    : :
    : : If your program compiles cleanly, but you still have problems, use
    : : the code tags, [leftbr]ode] and [leftbr]/code], and post the code.
    : :
    : : Good luck,
    : :
    : : bilderbikkel
    :
    : I make the changes for the headers..Now the programm running but
    : only for 0,5 second and close..i can't see it..Any ideas please?
    :
    : Here is the new [red]but still terrible laid out, not taking more then 5% of your comment into account, of the it-will-probably-not-do-what-I-inteded-but-nevertheless [/red]running programm:
    :
    : /*
    : mm1.cpp
    : */
    : #include
    : #include
    : #include
    : #include
    :
    : const CN_TSIM = 5000;
    : const CN_HOW_MANY_VALUES = 20;
    : const double CN_MIDDLE_RAND = CN_TSIM *2.4/
    : CN_HOW_MANY_VALUES;
    : const CN_LL = 8;
    : const CN_MM = 12;
    : const CN_MI =( CN_LL + CN_MM);
    : const double CN_PP = 1.0 * CN_LL / CN_MM;
    :
    : int expo( double &u)
    : {
    : double
    : e( rand()+ 1);
    : int
    : i( 0);
    : e /=( RAND_MAX+ 1);
    : e = exp( -e);
    : u = 1 - e;
    : e = - log( u) / CN_MI;
    : i =( int)( e * CN_MIDDLE_RAND);
    : return i;
    : }
    :
    : int main() {
    : const double P_ip1 =( double) CN_LL / ( CN_LL + CN_MM);
    : int
    : x( 0),
    : t( 0),
    : i( 0),
    : j( 0),
    : cust_in( 0),
    : cust_out( 0),
    : W[ 1+ CN_HOW_MANY_VALUES],hm[ 1+ CN_HOW_MANY_VALUES];
    : double
    : U( 0.0),
    : mpps( 0.0),
    : P[ 1+ CN_HOW_MANY_VALUES];
    : cout << "M/M/1" << endl << "------" << endl << endl;
    : srand(( unsigned) time( NULL));
    :
    : for( int k = 0; k <= CN_HOW_MANY_VALUES; k++)
    : P[ k] = hm[ k] = W[ k] = 0;
    : i = 1;
    : while( true)
    : { // compute 'x'
    : x = expo( U);
    : if(( t+ x) > CN_TSIM) {
    : W[ i] += ( CN_TSIM- t);
    : break;
    : }
    :
    : W[ i] += x;
    : t += x;
    : hm[ i]++;
    : // compute 'j'
    : if( U < P_ip1) {
    : if( i > 0) {
    : i = j = i - 1;
    : cust_out++;
    : }
    : }
    :
    : else {
    : if( i < CN_HOW_MANY_VALUES) {
    : i = j = i + 1;
    : cust_in++;
    : }
    : }
    : }
    :
    : for( int m = 1; m <= CN_HOW_MANY_VALUES; m++)
    : P[ m] =( double) W[ m] / CN_TSIM;
    : for( int n = 0; n <= CN_HOW_MANY_VALUES; n++) {
    : cout << "W[";
    : cout.width( 3);
    : cout << n << "]= ";cout.width( 4);
    : cout << W[ n] << ", P[";
    : cout.width( 3);
    : cout << n << "]= ";
    : cout.width( 5);
    : cout.setf( ios::fixed);
    : cout.setf( ios::showpoint);
    : cout.precision( 2);
    : cout << P[ n]*1e2 << " %, Afikseis: ";
    : cout.width( 3);
    : cout << hm[ n] << endl;
    : }
    :
    : cout << endl;
    [red]std::cin.get(); //Wait until the user presses return[/red]
    : return 0;
    : }
    :

    I'm too good for this world...
  • : : : : anybody to hepl me to run this program?? i can not fix it
    : : :
    : : : I see why you cannot fix it. You can't even _read_ it! Get your
    : : : layout right. Fix the warnings your compiler will emit. #include the
    : : : standard C++ header files (cstdlib, cstdlib, cmath) all without the
    : : : '.h'. Give your variables names readable names. Add comments better
    : : : then 'compute x'. Use asserts.
    : : :
    : : : If your program compiles cleanly, but you still have problems, use
    : : : the code tags, [leftbr]ode] and [leftbr]/code], and post the code.
    : : :
    : : : Good luck,
    : : :
    : : : bilderbikkel
    : :
    : : I make the changes for the headers..Now the programm running but
    : : only for 0,5 second and close..i can't see it..Any ideas please?
    : :
    : : Here is the new [red]but still terrible laid out, not taking more then 5% of your comment into account, of the it-will-probably-not-do-what-I-inteded-but-nevertheless [/red]running programm:
    : :
    : : /*
    : : mm1.cpp
    : : */
    : : #include
    : : #include
    : : #include
    : : #include
    : :
    : : const CN_TSIM = 5000;
    : : const CN_HOW_MANY_VALUES = 20;
    : : const double CN_MIDDLE_RAND = CN_TSIM *2.4/
    : : CN_HOW_MANY_VALUES;
    : : const CN_LL = 8;
    : : const CN_MM = 12;
    : : const CN_MI =( CN_LL + CN_MM);
    : : const double CN_PP = 1.0 * CN_LL / CN_MM;
    : :
    : : int expo( double &u)
    : : {
    : : double
    : : e( rand()+ 1);
    : : int
    : : i( 0);
    : : e /=( RAND_MAX+ 1);
    : : e = exp( -e);
    : : u = 1 - e;
    : : e = - log( u) / CN_MI;
    : : i =( int)( e * CN_MIDDLE_RAND);
    : : return i;
    : : }
    : :
    : : int main() {
    : : const double P_ip1 =( double) CN_LL / ( CN_LL + CN_MM);
    : : int
    : : x( 0),
    : : t( 0),
    : : i( 0),
    : : j( 0),
    : : cust_in( 0),
    : : cust_out( 0),
    : : W[ 1+ CN_HOW_MANY_VALUES],hm[ 1+ CN_HOW_MANY_VALUES];
    : : double
    : : U( 0.0),
    : : mpps( 0.0),
    : : P[ 1+ CN_HOW_MANY_VALUES];
    : : cout << "M/M/1" << endl << "------" << endl << endl;
    : : srand(( unsigned) time( NULL));
    : :
    : : for( int k = 0; k <= CN_HOW_MANY_VALUES; k++)
    : : P[ k] = hm[ k] = W[ k] = 0;
    : : i = 1;
    : : while( true)
    : : { // compute 'x'
    : : x = expo( U);
    : : if(( t+ x) > CN_TSIM) {
    : : W[ i] += ( CN_TSIM- t);
    : : break;
    : : }
    : :
    : : W[ i] += x;
    : : t += x;
    : : hm[ i]++;
    : : // compute 'j'
    : : if( U < P_ip1) {
    : : if( i > 0) {
    : : i = j = i - 1;
    : : cust_out++;
    : : }
    : : }
    : :
    : : else {
    : : if( i < CN_HOW_MANY_VALUES) {
    : : i = j = i + 1;
    : : cust_in++;
    : : }
    : : }
    : : }
    : :
    : : for( int m = 1; m <= CN_HOW_MANY_VALUES; m++)
    : : P[ m] =( double) W[ m] / CN_TSIM;
    : : for( int n = 0; n <= CN_HOW_MANY_VALUES; n++) {
    : : cout << "W[";
    : : cout.width( 3);
    : : cout << n << "]= ";cout.width( 4);
    : : cout << W[ n] << ", P[";
    : : cout.width( 3);
    : : cout << n << "]= ";
    : : cout.width( 5);
    : : cout.setf( ios::fixed);
    : : cout.setf( ios::showpoint);
    : : cout.precision( 2);
    : : cout << P[ n]*1e2 << " %, Afikseis: ";
    : : cout.width( 3);
    : : cout << hm[ n] << endl;
    : : }
    : :
    : : cout << endl;
    : [red]std::cin.get(); //Wait until the user presses return[/red]
    : : return 0;
    : : }
    : :
    :
    : I'm too good for this world...


    Thank you but this never run...you re sure that this run??

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories