- Joined
- Oct 24, 2021
- Posts
- 1,501
- Reaction
- 328
- Points
- 675
saan po ba mali or anong kulang ko po?
given;
inputs : 45 and 88
average output: 66.5
Attachments
-
You do not have permission to view the full content of this post. Log in or register now.
#include <iostream>
int main() {
int num1 = 45;
int num2 = 88;
double average = (num1 + num2) / 2.0;
std::cout << "The average is: " << average << std::endl;
return 0;
}
num1
and num2
to hold the input values of 45 and 88, respectively. Then, we calculate the average by adding the two numbers and dividing the sum by 2.0 to ensure it is a floating-point division. The result is stored in the average
variable.std::cout
.paano if yung user ang mag iinput?Based on the given inputs of 45 and 88, the correct average output should be 66.5. It seems like you have calculated the average correctly. However, without seeing your code or any specific problem you are facing, it is difficult to determine what might be wrong or missing.
To calculate the average of two numbers in C++, you can follow this simple code:
C++:#include <iostream> int main() { int num1 = 45; int num2 = 88; double average = (num1 + num2) / 2.0; std::cout << "The average is: " << average << std::endl; return 0; }
In this code, we declare two integer variablesnum1
andnum2
to hold the input values of 45 and 88, respectively. Then, we calculate the average by adding the two numbers and dividing the sum by 2.0 to ensure it is a floating-point division. The result is stored in theaverage
variable.
Finally, the average is printed to the console usingstd::cout
.
If you are facing a specific issue or if this code snippet does not match your implementation, please provide more details or your code so that we can help you identify the problem or missing parts.
To allow the user to input the values, you can modify the code to use thepaano if yung user ang mag iinput?
std::cin
function. Here's an example:#include <iostream>
int main() {
int num1, num2;
double average;
std::cout << "Enter the first number: ";
std::cin >> num1;
std::cout << "Enter the second number: ";
std::cin >> num2;
average = (num1 + num2) / 2.0;
std::cout << "The average is: " << average << std::endl;
return 0;
}
num1
and num2
to hold the user input values. We then prompt the user to enter the first and second numbers using std::cout
and read the input values using std::cin
.average
variable.std::cout
.salamat bossNag int "avg" ka para sa process boss pero ung tinawag mo ung variable na "average" kaya dump ung output niya, kung ano ung ginamit mo ayun din tawagin mo boss