| Novacain605 (6) | |
|
It's a problem from the "Engineering Problem Solving C++ 3rd edition" p. 302 #28: Write a program that simulates the deseign shown in Figure 6.17 using a component reliability of 0.8 for component 1, 0.85 for component 2, and 0.95 for component 3. Print the estimate of the reliability using 5,000 simulations. (The analytical reliability of the system is 0.794.) getting errors & I suck at this: #include<iostream> #include<cmath> #include<fstream> #include<cstdlib> using namespace std; double rand_float(double a, double b, double c); int main() { unsigned int seed; int n; double component_reliability, a_parallel, parallel_success(0), num1, num2, num3; cout << "Enter the indvidual component reliability: \n"; cin >> component_reliability; cout >> "Enter the number of trials: \n"; cin >> n; cout << "Enter unsigned integer seed: \n"; cin >> seed; srand(seed); cout << endl; a_parallel = 3*component_reliability,3) - 3*power(component_reliability,2) + pow(component_reliability,3); for (int k=1; k<=n; k++) { num1 = rand_float(0.1); num2 = rand_float(0.1); num3 = rand_float(0.1); if (((num1<=component_reliability) && ((num2<=component_reliability)) && (num3<=component_reliability)) { parallel_success++; } } cout << "Analytical Reliability \n"; cout << "Parallel: " << a_parallel << endl; cout << "Simulation Reliability " << n << " trials \n"; cout << " Parallel: " << (double)parallel_success/n << endl; system ("PAUSE"); return 0; } double rand_float(double a, double b) { return ((double)rand()/RAND_MAX*(b-a) + a; } | |
|
|
|
| cire (1845) | ||
Provide the text of the errors. Use code tags. Look for the <> button.
| ||
|
|
||
| Novacain605 (6) | |
|
C:\Users\owner\Documents\cse206>g++ prog4.cpp prog4.cpp: In function 'int main()': prog4.cpp:18:10: error: no match for 'operator>>' in 'std::cout >> "Enter the nu mber of trials: \012"' prog4.cpp:18:10: note: candidates are: c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/basic_string.tcc:998:5: n ote: template<class _CharT, class _Traits, class _Alloc> std::basic_istream<_Cha rT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, std::basic_s tring<_CharT, _Traits, _Alloc>&) c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/istream.tcc:957:5: note: template<class _CharT2, class _Traits2> std::basic_istream<_CharT, _Traits>& std ::operator>>(std::basic_istream<_CharT, _Traits>&, _CharT2*) c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/bits/istream.tcc:925:5: note: template<class _CharT, class _Traits> std::basic_istream<_CharT, _Traits>& std:: operator>>(std::basic_istream<_CharT, _Traits>&, _CharT&) c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/istream:709:5: note: template< class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_ist ream<char, _Traits>&, unsigned char&) c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/istream:714:5: note: template< class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_ist ream<char, _Traits>&, signed char&) c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/istream:756:5: note: template< class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_ist ream<char, _Traits>&, unsigned char*) c:\mingw\bin\../lib/gcc/mingw32/4.6.2/include/c++/istream:761:5: note: template< class _Traits> std::basic_istream<char, _Traits>& std::operator>>(std::basic_ist ream<char, _Traits>&, signed char*) prog4.cpp:25:40: error: expected ';' before ')' token prog4.cpp:30:24: error: too few arguments to function 'double rand_float(double, double, double)' prog4.cpp:8:12: note: declared here prog4.cpp:31:24: error: too few arguments to function 'double rand_float(double, double, double)' prog4.cpp:8:12: note: declared here prog4.cpp:32:24: error: too few arguments to function 'double rand_float(double, double, double)' prog4.cpp:8:12: note: declared here prog4.cpp:36:3: error: expected ')' before '{' token prog4.cpp:39:2: error: expected primary-expression before '}' token prog4.cpp:39:2: error: expected ';' before '}' token prog4.cpp: In function 'double rand_float(double, double)': prog4.cpp:52:44: error: expected ')' before ';' token | |
|
|
|
| cire (1845) | |||
If you navigate to the error the line occurs (line 2 in the snippet above) and you look at the previous use of cout which did not result in an error (line 1 in the snippet above) do you notice any differences? | |||
|
|
|||
| AbstractionAnon (412) | |
|
In addition to the improper use of cout that cire mentioned you have the foloowing problems also: Line 8: rand_float is declared to take 3 arguments. Line 30,31,32: rand_float is called with only one argument. Does not match the forward declaration at line 8. Line 50: Implementation of rand_float takes 2 arguments. This doesn't match either the prototype or the calls. Prototype, calls and implementation MUST match. Line 25: Unmatched parenthises. Line 32: Extraneous parenthises Line 52: Unmatches parenthises PLEASE USE CODE TAGS (the <> formatting button) when posting code. It makes it easier to respond to your post. | |
|
|
|
| Novacain605 (6) | |
| ok thanks for trying to help guys...I'm working on it now | |
|
|
|