Hi my code is working except the final part where I test whether the sum of probabilities is equal 1 or not. I am new in this field and I guess that is the reasson I just cannot find any mistake. Th euser needs to enter 3 numbers which sum is one. And if they enetr it wrongly, teh program should let them know.
I would really appreciate any help!!!!!
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
Code:
main ()
{
ofstream os;
ifstream is;
os.open("d:\\Branka\\lit review\\programming\\Prep\\intro.txt");
if(os.fail())
{
cout << " Output file opening failed. \n";
exit(1);
}
os.setf(ios::fixed);
os.setf(ios::showpoint);
os.precision(3);
int a;
float num;
float sum=0;
float small=1e-2;
cout <<"\nPlease enter the probability values for RIF1 or Training for recovery within the team/ATC Centre.";
cout <<"\nThere are three possible Levels of influence of this paricular RIF.";
cout <<"\nYou need to enter corresponding probabilities for each Level so that the sum equals one (e.g. 0.33, 0.33, 0.33).";
cout <<"\nIf one Level corresponds precisely to the event under description, simply enter zero to the other boxes (e.g. 0, 1, 0 or 0.5, 0, 0.5).";
cout <<"\nPlease enter three values separarted with the space: ";
for (a=0; a<3; a++)
{
cin >> num;
os <<"The RIF Level "; os << (a+1); os << " is: "; os << num; os << endl;
sum +=num;
}
if ((sum>=1.00-small)&&(sum<=1.00+small))
{cout << "The input is verified, move on to the next RIF!\n";}
else
{cout << " The sum of your inputs is not 1, but"; cout << sum;
cout << "! Input the probabilities so that their sum equals 1.\n";}
os << "The sum of your inputs is "; os << sum; os << endl;
return 0;
}