Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,645 members, 7,809,429 topics. Date: Friday, 26 April 2024 at 09:27 AM

help me with this in c++ - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / help me with this in c++ (1033 Views)

Creating UWP Application In C# Or C++ (xaml) / Tutorial: Building A Simple Fraction Arithmetic Program In C# Using TDD / [problem] Write A Program In C++ That Finds The Hcf Of 2 Numbers Without Using A Recursive Function (2) (3) (4)

(1) (Reply) (Go Down)

help me with this in c++ by lifeisgood32: 4:51pm On Aug 12, 2012
Here is the problem,
Demand 0 2 3 4 5
Prob 1/10 ¼ ½ 1/10 1/20

Obtain the process generator and monte Carlo algorithm.
Write a program to simulate the demands for the next 100days.
Will paste my codes.
Re: help me with this in c++ by lifeisgood32: 5:40pm On Aug 12, 2012
#include < iostream>
#include <c.stdlib>
#include < c.time>



using namespace std;

void getHits (int arr[], int R);
float getprobability (int num, int count);
float probability [5];
int main ( int argc, Char* argv []){
//declare hits array
int hits[5]={0,0,0,0,0}
int n;
cout<< ¨input the number of time u want to simulate¨<<endl;
cin>> n;
getHits (Hits, n);
for( int i=0; i < 1; i++){
cout<< ¨numbers of hits for J¨ << i+1 << ¨ is¨ <<probability [1]<< endl;
}
system (¨pause¨);

return 0;



void getHits (int arr[], int n){
int irandomNumber;
float randomNumber;

Srand (time(NULL));
for (int i=0; i < n; i++){
irandomNumber = rand()% 100;
randomNumber = static_cast <float>(irandomNumber)/2.0f;
if (randomNumber >= 0 && randomNumber <= (0.10f))arr[0]++;
if (randomNumber >= (0.10f) && randomNumber <= (0.35f))arr[2]++;
if (randomNumber >= (0.35f) && randomNumber <=(0.85f)) arr[3]++;
if (randomNumber >= (0.85f) && randomNumber <= (0.95f))arr[4]++;
if (randomNumber >= (0.95f) && randomNumber <= (1.0))arr[5]++;
}

for (int i=0; i<1; i++){

probability[i] = getprobability(arr[i], n);
}

float getprobability ( int num, int count){
return float((float)num/count);
}
Re: help me with this in c++ by lifeisgood32: 5:43pm On Aug 12, 2012
Am sorry if my codes are not well arranged am using my phone, i really appreciate for giving me your time.
Re: help me with this in c++ by lordZOUGA(m): 6:42pm On Aug 12, 2012
Mehn... I just told you to rename the other thread and you had to create another thread with my name? How exactly do you expect other programmers to help with their inputs?
Please rename the thread to a more general name like "help with C++ code".. To do that modify the first post
Re: help me with this in c++ by lifeisgood32: 8:17pm On Aug 12, 2012
okay sorry for the mixup i didnt get ur message clear.
Re: help me with this in c++ by lordZOUGA(m): 3:11pm On Aug 14, 2012
your include statements are off...
Use the other code I wrote for you as template... You shold be able to correct most of your syntax errors...
I look at your code, I know it wants to solve the problem you posted above but I don't understand what path you are approaching it from. Please apply comments to relevant parts of the code..

(1) (Reply)

Should Nairaland Forum Be Made A Downloadable Application For Phones? / Master's Degree In Computer Programming In UK. Please Advice. / FORTRAN 2003 Programming!

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 11
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.