Hi there,
it is homeworkthe calculation!!!
im trying to use functions (not homework)
i would like do it without arrays (not homework)
I need a little bit help with the error message
error C2448: '<Unknown>' : function-style initializer appears to be a function definition
the message appears if i compile and the compiler stops by line 99 and 117 (functions)
and i need some good ideas to make the code really good (ANSI), maybe easier and shorter than now!
how can i use float average and not double?
Thanks for your help
here the code:
//C++ program that reads a series of integer numbers (between 0 and 100), calculates and prints
//sum of first and last numbers
//average of first three numbers
//product of last two numbers
//largest of all numbers
//greatest common divisor(gcd) of last two numbers
//factorial of last two numbers
//grade for all numbers (H:85-100, D:75-84, C65-74, P:50-64, F:0-49)
//Constant and type definitions are included in header file.
#include <iostream.h> // header file for input/output stream
#include <stdlib.h> // header file for standard library
#include <math.h> // header file for mathmatic
int first_number;
int second_number;
int third_number;
int fourth_number;
int last_number;
// function prototypes
int sum;
double average;
double product;
int largest;
double gcd;
int factorial;
int grade;
------
// function main begins program execution
int main()
{
cout << "Welcome to my program";
cout << "This program calculate and print the following things: ";
cout << "The sum of first and last numbers";
cout << "The average of first three numbers";
cout << "The product of last two numbers";
cout << "The largest of all numbers";
cout << "The greatest common divisor(gcd) of last two numbers";
cout << "The factorial of last two numbers";
cout << "and";
cout << "The grade for all numbers (H:85-100, D:75-84, C65-74, P:50-64, F:0-49)";
cout << endl << endl;
cout;
cout << endl << endl;
cout << "Enter first integer: ";
cin >> first_number;
cout << "Enter second integer: ";
cin >> second_number;
cout << "Enter third integer: ";
cin >> third_number;
cout << "Enter fourth integer: ";
cin >> fourth_number;
cout << "Enter last (first 3 digits of your ID-number) integer: ";
cin >> last_number;
// numbers one and last are arguments to the sum function call
cout << "The sum of the first and last numbers " << first_number << ", " << last_number << "is: " << sum << endl;
// numbers 1 to 3 are arguments to the average function call
cout << "The average of the first three numbers " << first_number << ", " << second_number << ", " << third_number <<" is: " << average << endl;
// numbers of last two numbers are arguments to the product function call
cout << "The product of the last two numbers " << fourth_number << ", " << last_number << "is: " << product << endl;
// numbers 1 to last are arguments to the largest function call
cout << "The largest number " << first_number << ", " << second_number << ", " << third_number << ", " << fourth_number << ", " << last_number << "is: " << largest << endl;
// last two numbers are arguments to the gcd function call
cout << "The product of the last two numbers " << fourth_number << ", " << last_number << "is: " << gcd << endl;
// last two numbers are arguments to factorial function call
cout << "The factorial of the last number " << last_number << "is: " << factorial << endl;
// all numbers are arguments to grade function call
cout << "The largest number " << first_number << ", " << second_number << ", " << third_number << ", " << fourth_number << ", " << last_number << "is: " << grade << endl;
return 0; // indicates successful termination
} // end main
---------
// function average of first three numbers definition;
double average (first_number, second_number, third_number)
{
average =(first_number + second_number + third_number + 0.0) / 3; //calculates the average of first three numbers numbers
return average;
} // end function average
----------
// funtion product of last two numbers definition;
// function largest number definition;
int largest (first_number, second_number, third_number, fourth_number, last_number)
{
int large = first_number; // assume first_number is largest
if (second_number > large) // if sec_number is larger, assign sec_number to max
large = second_number;
if (third_number > large) // if third_number is larger, assign third_number to max
large = third_number;
if (fourth_number > large) // if fourth_number is larger, assign fourth_number to max
large = fourth_number;
if (last_number > large) // if last_number is larger, assign last_number to max
large = last_number;
return large; // large is largest value
} // end function largest
/*
-----------
//function to calculate factorial
int factorial(int last_number)
{
if (last_number > 1) {
return n * factorial(n - 1);
}
else {
return 1;
}
}
-------------
//function to calculate grade of all numbers
if (numericGrade <= 100) {
letterGrade = 'H';
} else if (numericGrade >= 84) {
letterGrade = 'D';
} else if (numericGrade <= 74) {
letterGrade = 'C';
} else if (numbericGrade <= 64) {
letterGrade = 'P';
} else if (numericGrade <= 49){
letterGrade = 'F';
}
}
*/