+ 2

check multiple of 5

how can I write a code using c++ which accepts a number and rounds the number off to the next multiple of 5 example: user inputs 78 and it gets rounded off to 80. thank you.

7th Jun 2019, 2:57 PM
Tewogbade Bamidele
Tewogbade Bamidele - avatar
4 Respostas
7th Jun 2019, 3:48 PM
minirkk
minirkk - avatar
+ 3
roundoff() { int i; cout<<"Enter a number"; cin>>i; if((i%5)!=0) { i+=(5-i%5); return i; } else return i; } //Now call this function from main()
7th Jun 2019, 5:44 PM
Pranjal Dahal
Pranjal Dahal - avatar
+ 1
Use a loop and for checking the multiple => modulus operator "%"
7th Jun 2019, 3:09 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
thank you for your answers really helped me
7th Jun 2019, 3:59 PM
Tewogbade Bamidele
Tewogbade Bamidele - avatar