Hello there, I'm new with C++, I have a program in C++ that runs fine in devC++ using compile&run feature, but when I click to that application, it works not right.
When I hit number 1 or 2 or 3, then enter, it should do some calculation and print out something. But in application, after 1 or 2 and enter, it exits.
Can someone check it out for me, I have tested this in another computer and another c++ software, same issue.
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <math.h>
usingnamespace std;
float random( float min, float max )
{
float scale = rand() / ((double) RAND_MAX);
return min + scale * ( max - min );
}
int main()
{
srand((int) time(NULL));
int m,n,k,z;
float lamda;
do
{
cout<<"Chuong trinh mo phong he thong truyen tin"<<endl;
cout<<"Vui long chon bo tham so"<<endl;
cout<<"1. n=7; m=4; k=3; lamda=0.00002"<<endl;
cout<<"2. n=10; m=7; k=3; lamda=0.00001"<<endl;
cout<<"3. tuy chon"<<endl;
int z =1;
cin>>z;
if(z==1){
n=7,m =4,k =3;
lamda = 0.00002;}
elseif(z==2){
n=10,m =7,k =3;
lamda = 0.00001;}
elseif(z==3){
cout<<"nhap gia tri n: ";
cin>>n;
cout<<"nhap gia tri m : ";
cin>>m;
cout<<"nhap gia tri k: ";
cin>>k;
cout<<"nhap gia tri lamda: ";
cin>>lamda;
}}
while(m<=0 or n<=0 or k<=0 or lamda<=0);
int Q0=0,Q1=0;
int S=3000;
for(int i=0;i<S;i++)
{
double X = random(0,1);
double Y= -log(X);
int T= Y/lamda;
int PN= T/n;
if(T>=n){
Q0=Q0+ PN;
double PL=T-PN*n;
if(PL>0){
Q1=Q1+1;
}
}
else {
Q1=Q1+1;
}
}
float PS=double(Q0)/(double(Q0+Q1));
float PD=1-PS;
float V=m*(1-PS)/n;
cout<<"so lan truyen tin sai Q1 = "<<Q1<<endl;
cout<<"so lan truyen tin sai Q0 = "<<Q0<<endl;
cout<<"3. tuy chon";
cout<<"voi cuog do hong hoc lamda = "<<lamda<<"l/h"<<" va chieu dai tu ma la "<<n<<"("<<m<<","<<k<<")"<<endl;
cout<<"Xac suat sai la Ps:"<<PS<<endl;
cout<<"Xac suat dung la Pd:"<<PD<<endl;
cout<<"Toc do truyen tin la V:"<<V<<endl;
}
Runs OK without crashing using XCode and cppshell. Of course the Vietnamese, without being translated, means zip to me.
Chuong trinh mo phong he thong truyen tin
Vui long chon bo tham so
1. n=7; m=4; k=3; lamda=0.00002
2. n=10; m=7; k=3; lamda=0.00001
3. tuy chon
3
nhap gia tri n: 1
nhap gia tri m : 2
nhap gia tri k: 4
nhap gia tri lamda: 33
so lan truyen tin sai Q1 = 3000
so lan truyen tin sai Q0 = 0
3. tuy chonvoi cuog do hong hoc lamda = 33l/h va chieu dai tu ma la 1(2,4)
Xac suat sai la Ps:0
Xac suat dung la Pd:1
Toc do truyen tin la V:2