What's new

C & C++ C++ help

Augustus69

Forum Veteran
Established
Joined
Oct 24, 2021
Posts
1,482
Reaction
326
Points
667
IMG20230921235521.jpg

saan po ba mali or anong kulang ko po?

given;
inputs : 45 and 88
average output: 66.5
 

Attachments

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 variables 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.

Finally, the average is printed to the console using std::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.
 
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 variables 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.

Finally, the average is printed to the console using std::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.
paano if yung user ang mag iinput?
 
paano if yung user ang mag iinput?
To allow the user to input the values, you can modify the code to use the std::cin function. Here's an example:

C++:
#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;
}

In this code, we declare the integer variables 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.

After obtaining the input values, we calculate the average as before, by adding the two numbers and dividing the sum by 2.0. The result is stored in the average variable.

Finally, we output the average to the console using std::cout.

Now, when you run the program, it will prompt the user to enter the two numbers, calculate the average, and display the result.
 
Nag 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
 
na fix naba?

yung declaration mosa avg din gawin mong float para din accurate, if ever may nag input ng float type
 

Similar threads

Back
Top