dimanche 24 janvier 2021

Can I put a range fo the user input on C++?

I need the user to input 7 numbers, they cant be smaleer than 0 or bigger than 10.Im aware i could do it with an IF or WHILE, but I'm not supposed to use them. Here is my code (It gets the avg of 7 scores with two decimals).

    #include <iostream>
    #include <iomanip> 
    using namespace std;

    int main(){
    float c1, c2, c3, c4, c5, c6, c7;
    float promedio = 0;

    cin>> c1 >> c2 >> c3 >> c4 >> c5 >> c6 >> c7;
    promedio = (c1+c2+c3+c4+c5+c6+c7)/7;
    cout<< setprecision(2) << promedio <<'\n';

    }

Aucun commentaire:

Enregistrer un commentaire