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:
/*somme.cpp */
#include <iostream>
using namespace std;
//Sum of two numbers
int failableFunction()
{
double sum =0;
double value[40];
int result=0;
for (int i = 0; i < 40; ++i )
{
cout << "Enter value: " << i << ": ";
cin >> value[ i ];
sum += value[ i ];
}
if (result != 0 )//this line here or in the main ?
{
cout << "Function call failed: "<< result;
if (static_cast<int>(value[ i ])== 36 )//36 is ASCII of $//: error: name lookup of ‘i’ changed for ISO ‘for’ scoping [-fpermissive]
{
cout << "Here is the sum : " <<sum<<endl;
double nomb=i;
cout << "Here is the average value: " << sum / nomb << endl;
return 0;
}
}
}
int main ()
{
cout << "Here is the addition of many numbers (even with a .).MAXIMUM OF NUMBERS=39 : \n";
cout << "Once you have finished your list of numbers, hit $ for indicating the end \n";
const int result = failableFunction();
if (result != 0 ) cout << "Function call failed: " << result ;//this line here or in tha function ?
}
/*somme.cpp */
#include <iostream>
using namespace std;
//Sum of two numbers
int failableFunction()
{
double sum =0;
double value[40];
int result=0;
for (int i = 0; i < 40; ++i )
{
cout << "Enter value: " << i << ": ";
cin >> value[ i ];
sum += value[ i ];
}
if (result != 0 )//this line here or in the main ?
{
cout << "Function call failed: "<< result;
if (static_cast<int>(value[ i ])== 36 )//36 is ASCII of $//: error: name lookup of ‘i’ changed for ISO ‘for’ scoping [-fpermissive]
{
cout << "Here is the sum : " <<sum<<endl;
double nomb=i;
cout << "Here is the average value: " << sum / nomb << endl;
return 0;
}
}
}
int main ()
{
cout << "Here is the addition of many numbers (even with a .).MAXIMUM OF NUMBERS=39 : \n";
cout << "Once you have finished your list of numbers, hit $ for indicating the end \n";
const int result = failableFunction();
if (result != 0 ) cout << "Function call failed: " << result ;//this line here or in tha function ?
}
To copy to clipboard, switch view to plain text mode
Bookmarks