Tuesday, October 15, 2013

uri online judge 1005 solution in c++

hello folks, it is really getting funny
here is uri online judge 1005 problem: http://www.urionlinejudge.com.br/judge/en/problems/view/1005

Average 1

Make a simple program that read two floating numbers corresponding to two tests for a student. After, calculate the average between them, considering that the first number has 3.5 weight and the second one have 7.5 weight. Each number can be from zero to ten, always with one digit after the decimal point. Don’t forget to print end line after the result otherwise you will get “Presentation Error”. Don’t forget the space before and after the equal sign.

Input

The input file will contain 2 floating-point numbers with one digit after the decimal point.

Output

Print MEDIA(average in portuguese) according to the following example, with 5 digits after the decimal point and a blank space before and after the equal signal.
Sample InputSample Output
5.0
7.1
MEDIA = 6.43182

and here is my solution in c++ for uri online judge 1005: http://ideone.com/d80A5r


  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. int main() {
  6. double x, y, MEDIA;
  7. cin >> fixed >> setprecision(1);
  8. cin >> x >> y;
  9. MEDIA = ((x * 3.5) + (y * 7.5)) / (3.5 + 7.5);
  10. cout << fixed << setprecision(5);
  11. cout << "MEDIA = " << MEDIA << endl;
  12. return 0;
  13. }

3 comments:

  1. How did you make the function ?
    MEDIA = ((x * 3.5) + (y * 7.5)) / (3.5 + 7.5);
    I don't get I am sorry can you explain it please

    ReplyDelete