Monday, May 30, 2016

URI Online Judge Solution| 1118 Several Scores with Validation

URI Online Judge | 1118

Several Scores with Validation

By Neilor Tonin, URI  Brazil
Timelimit: 1
Write an program to read two scores of a student. Calculate and print the semester average. The program must accept only valid scores (a score must fit in the range [0.10]). Each score must be validated separately.
The program must print a message "novo cálculo (1-sim 2-nao)" that means "new calculate (1-yes 2-no)". After, the input will be (1 or 2). 1 means a new calculation, 2 means that the execution must be finished.

Input

The input file contains several positive or negative floating-point (double) values​. After the input of 2 valid scores, an integer number X will be read. Your program must stop when X = 2.

Output

If an invalid score is read, must be printed the message "nota inválida". When two valid scores are read, the message "media = " must be printed folowed by the average between these 2 scores. The message "novo cálculo (1-sim 2-nao)" must be printed after reading X. This message should be displayed again if the standard input number for X is less than 1 or greater than 2, as example below.
The output average must be printed with 2 digits after the decimal point.
Input SampleOutput Sample
-3.5
3.5
11.0
10.0
4
1
8.0
9.0
2
nota invalida
nota invalida
media = 6.75
novo calculo (1-sim 2-nao)
novo calculo (1-sim 2-nao)
media = 8.50
novo calculo (1-sim 2-nao)

URI Online Judge  Solution| 1118 Several Scores with Validation in C++

#include <iostream>
#include <iomanip>
 
using namespace std;
 
int main()
{
    float x = -1, y = -1;
    int value = 1;
 
    while(value == 1)
    {
        do{
            cin >> x;
            if(x < 0 || x > 10)
                cout << "nota invalida" << endl;
 
        }while(x < 0 || x > 10);
 
        do{
            cin >> y;
            if(y < 0 || y > 10)
                cout << "nota invalida" << endl;
 
        }while(y < 0 || y > 10);
 
        cout << "media = " << fixed << setprecision(2) << ((x + y) / 2) << endl;
 
        do{
            cout << "novo calculo (1-sim 2-nao)" << endl;
            cin >> value;
 
        }while(value != 1 && value != 2);
    }
 
    return 0;
}


This is a simple score validation program. For clearing more read the question again and again. Logic is so simple. Just code what says in the problem.
For beginner: Here since I have to first check the number that means I've to enter the loop first, so I apply here do-while loop. 

Download code from dropbox
URI Link



No comments:
Write comments

To know more about the problem, give us your valuable commment. We'll try to help you. Thanks

All rights reserved ©2016 -URI ONLINE JUDGE SOLUTION | Developed by Maniruzzaman Akash

© 2016 URI ONLINE JUDGE SOLUTION. Developed by Maniruzzaman Akash | Distributed By Gooyaabi Templates
Powered by Blogger.