0
can someone please point out my mistakes , I don't get what is wrong.
/*i want to make a hour to min convertor , but for some reason there are piles of errors showing up ,much bigger than my code plz only point out my mistakes */ #include <iostream> void tomin(int *htpr) { *htpr*=60; std::cout << min; } int main() { int hours; std::cin>>hours; int *htpr; htpr = &hours; std::cout << tomin(htpr); }
7 Respostas
+ 1
Yes. And You can use int return type and return calculated result......
+ 1
// this is my eddited code but still not giving out the exoected output
#include <iostream>
int tomin(int *htpr)
{
*htpr*=60;
}
int main()
{
int hours ;
std::cin>>hours;
int *htpr;
htpr = &hours;
std::cout << tomin(htpr);
std::cout << hours;
return 0;
}
0
Your function is void type so it don't return anything.. But you expecting to return a value in last statement.
also min is undfined in function. first declars it then assign value and use to print.
0
you mean the cout function do0es't work in void
0
what if I add int tomin(*hptr)
0
if i use
std::cout << hours ;
in function the outcome is the same
0
#include <iostream>
int tomin(int *htpr)
{
*htpr*=60;
return *htpr; //because return type int, you should return a int value.
}
int main()
{
int hours;
std::cin>>hours;
int *htpr;
htpr = &hours;
std::cout << tomin(htpr);
std::cout << hours;
//both output same
return 0;
}
//since you are doing pass by pointers, this is enough.
#include <iostream>
void tomin(int *htpr)
{
*htpr*=60;
}
int main()
{
int hours;
std::cin>>hours;
int *htpr = &hours;
tomin(htpr);
std::cout << hours;
return 0;
}
// without *htpr, use as tomin(&hour);