I have a new file. It compiles well. The thing that goes wrong is that the loop goes to 40, even if I enter $. So the last i=40. Therefore my control of the ASCII cannot work. I hope I will have some aid of you. Thanks.
/*stranz.cpp */
#include <iostream>
using namespace std;
//global variables
double sum=0;
double value[40];
int i=0;
int failableFunction()
{
//double value[40]
cout << "good morning\n";
for ( i = 0; i < 40; ++i )
{
cout << "Enter value: " << i << ": ";
cin >> value[ i ];
sum += value[ i ];
}
}
int main ()
{
cout << "Here is the addition of many numbers (even with a .).MAXIMUM OF NUMBERS=40\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 << endl;
cout << value[ 0 ] << ' '<< i <<' '<<value[ i ] << endl;
if (static_cast<int>(value[ i ])== 36 )//36 is ASCII of $
{
cout << "Here is the sum: " << sum<<endl;
double nomb=i;
cout << "Here is the average value: " << sum / nomb << endl;
}
return 0;
}
}
~
~
/*stranz.cpp */
#include <iostream>
using namespace std;
//global variables
double sum=0;
double value[40];
int i=0;
int failableFunction()
{
//double value[40]
cout << "good morning\n";
for ( i = 0; i < 40; ++i )
{
cout << "Enter value: " << i << ": ";
cin >> value[ i ];
sum += value[ i ];
}
}
int main ()
{
cout << "Here is the addition of many numbers (even with a .).MAXIMUM OF NUMBERS=40\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 << endl;
cout << value[ 0 ] << ' '<< i <<' '<<value[ i ] << endl;
if (static_cast<int>(value[ i ])== 36 )//36 is ASCII of $
{
cout << "Here is the sum: " << sum<<endl;
double nomb=i;
cout << "Here is the average value: " << sum / nomb << endl;
}
return 0;
}
}
~
~
To copy to clipboard, switch view to plain text mode
Bookmarks