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); }

22nd Jun 2022, 5:43 PM
sahil somyani
sahil somyani - avatar
7 Answers
+ 1
Yes. And You can use int return type and return calculated result......
22nd Jun 2022, 5:59 PM
Jayakrishna 🇼🇳
+ 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; }
22nd Jun 2022, 6:08 PM
sahil somyani
sahil somyani - avatar
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.
22nd Jun 2022, 5:54 PM
Jayakrishna 🇼🇳
0
you mean the cout function do0es't work in void
22nd Jun 2022, 5:55 PM
sahil somyani
sahil somyani - avatar
0
what if I add int tomin(*hptr)
22nd Jun 2022, 5:56 PM
sahil somyani
sahil somyani - avatar
0
if i use std::cout << hours ; in function the outcome is the same
22nd Jun 2022, 6:10 PM
sahil somyani
sahil somyani - avatar
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);
22nd Jun 2022, 6:28 PM
Jayakrishna 🇼🇳