HI all! With the book of Alex Allain I try to finish this file. I think, being alone, I will never succeed. May someone help me. Here is the code:
Qt Code:
  1. /*somme.cpp */
  2. #include <iostream>
  3. using namespace std;
  4. //Sum of two numbers
  5. int failableFunction()
  6. {
  7. double sum =0;
  8. double value[40];
  9. int result=0;
  10. for (int i = 0; i < 40; ++i )
  11. {
  12. cout << "Enter value: " << i << ": ";
  13. cin >> value[ i ];
  14. sum += value[ i ];
  15. }
  16. if (result != 0 )//this line here or in the main ?
  17. {
  18. cout << "Function call failed: "<< result;
  19.  
  20. if (static_cast<int>(value[ i ])== 36 )//36 is ASCII of $//: error: name lookup of ‘i’ changed for ISO ‘for’ scoping [-fpermissive]
  21.  
  22. {
  23. cout << "Here is the sum : " <<sum<<endl;
  24. double nomb=i;
  25. cout << "Here is the average value: " << sum / nomb << endl;
  26. return 0;
  27. }
  28.  
  29. }
  30. }
  31. int main ()
  32. {
  33. cout << "Here is the addition of many numbers (even with a .).MAXIMUM OF NUMBERS=39 : \n";
  34. cout << "Once you have finished your list of numbers, hit $ for indicating the end \n";
  35. const int result = failableFunction();
  36. if (result != 0 ) cout << "Function call failed: " << result ;//this line here or in tha function ?
  37.  
  38. }
To copy to clipboard, switch view to plain text mode