- 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; }
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;
}
+ 2
You should show the output from the toMinutes method:
void toMinutes(int hours){
int inMinute = hours*60;
cout<<inMinute;
}
+ 2
Rellot's screwdriver , of course it's better, but he need to change using a void function
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);
}
0
#include <iostream>
using namespace std;
void toMinutes(int hours){
cout<<hours*60;
};
int main(){
int x;
cin>>x;
toMinutes(x);
return 0;
}
0
#include<iostream>
using namespace std;
void toMinutes(int& hours)
{
hours *= 60;
}
int main()
{
int hours;
cin >> hours;
toMinutes(hours);
cout << hours;
}
Good Luck