something really simple....
This is supposed to be an easy one, but I can't get it to work right..
Could anyone please help?
------------------------------------
Code:
---------------------------------
int main ()
{
int num1, num2;
float sum, average;
num1=0; num2=0;
sum = num1 + num2;
average = (num1 + num2) / 2.0;
cout << "This program calculates the sum and average of two input integers." << endl;
cout << "Please enter two integers separated by a space: ";
cin >> num1 ; num2;
cout << endl;
// Add num1 + num2 for the sum.
sum = num1 + num2;
// Average of num1 and num2.
average = (num1 + num2) / 2.0;
// Display the sum of num1 + num2.
cout << "The sum of your two numbers is " << sum << endl;
// Display the average of num1 and num2.
cout << "The average of your two numbers is " << average << endl << endl;
return 0;
}
Re: something really simple....
Code:
int main ()
{
int num1, num2;
float sum, average;
num1=0; num2=0;
sum = num1 + num2; //These two lines are
average = (num1 + num2) / 2.0; //doing nothing valuable.
cout << "This program calculates the sum and average of two input integers." << endl;
cout << "Please enter two integers separated by a space: ";
cin >> num1 ; num2; // Here's your biggest problem.
//Change that line to cin >> num1 >> num2;
cout << endl;
// Add num1 + num2 for the sum.
sum = num1 + num2;
// Average of num1 and num2.
average = (num1 + num2) / 2.0; //It'd be better to use your sum variable rather that do the same computation twice.
// Display the sum of num1 + num2.
cout << "The sum of your two numbers is " << sum << endl;
// Display the average of num1 and num2.
cout << "The average of your two numbers is " << average << endl << endl;
return 0;
}
That ought to fix everything necessary. Also, sum could be an int. And when you open a tag like code, you need to close it with [ /code ], except without those spaces.