- 1

Hours to Minutes VOID PROBLEM

I need to change hours to minutes using a void function You are building an Hours to Minutes converter. Complete the given function so that it will take from user the count of hours as an argument, convert them into minutes, and output. Sample Input 5 Sample Output 300 I tried: #include <iostream> using namespace std; //your function void toMinutes(int hours) { toMinutes = hours * 60; } int main() { int x; cin >> x; toMinutes(x); return 0; } and original is: #include <iostream> using namespace std; //your function void toMinutes(int hours) { //complete the function } int main() { //call the function return 0; }

3rd Aug 2021, 2:36 PM
vilrau12
vilrau12 - avatar
6 Respostas
+ 6
You can use references: #include<iostream> using namespace std; void toMinutes(int& hours) { hours *= 60; } int main() { int hours; cin >> hours; toMinutes(hours); cout << hours; }
3rd Aug 2021, 2:48 PM
Roma Butaku
Roma Butaku - avatar
+ 2
You should show the output from the toMinutes method: void toMinutes(int hours){ int inMinute = hours*60; cout<<inMinute; }
3rd Aug 2021, 2:43 PM
Baribor Saturday
Baribor Saturday - avatar
+ 2
Rellot's screwdriver , of course it's better, but he need to change using a void function
3rd Aug 2021, 2:52 PM
Roma Butaku
Roma Butaku - avatar
0
well. it's better to just print that whole function out in main instead of making an Output operation in function, which is considered a messy code(just a wildguess) you also didn't input a datatype in inMinutes variable. here's my approach lol int toMinutes(int hours){ return hours * 60; } int main(){ using namespace std; int user_input; cin >> user_input; cout << toMinutes(user_input); }
3rd Aug 2021, 2:50 PM
Rellot's screwdriver
Rellot's screwdriver - avatar
0
#include <iostream> using namespace std; void toMinutes(int hours){ cout<<hours*60; }; int main(){ int x; cin>>x; toMinutes(x); return 0; }
23rd Dec 2021, 7:33 PM
Marco Ranieri
0
#include<iostream> using namespace std; void toMinutes(int& hours) { hours *= 60; } int main() { int hours; cin >> hours; toMinutes(hours); cout << hours; } Good Luck
25th Jan 2022, 5:04 PM
Muhammad Alif Deva Rizqon
Muhammad Alif Deva Rizqon - avatar