next time please use code tag. It will make code simpler to read.
Your problem is that Num function will have infinite while loop in it.
While loop looks like this:
1 2 3 4
while(condition)
{
code
}
and if integer inside condition of while is equal to 0 - while loop stops.
Otherwise, it will run.
56 % 10 = 6. You never increment or change 56, so it will always check for result of 56%10. You have to change this part of code.
Just from the looks of this code I would guess you want to output the remainder with a function?
If so you could do this...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include<iostream>
#include<conio.h>
usingnamespace std ;
int Num(int z){
int i = z % 10;
return i ;
}
int main(){
cout<<Num(56)<<endl ;
getch();
return 0 ;
}
Manga ..... i am actually trying to cout the digits in any number
#include<iostream>
#include<conio.h>
using namespace std ;
int Num(int z){
int i = 0 ;
while(z % 10){
z = z / 10 ;
i++ ;
}
return i ;
}
int main(){
cout<<Num(56)<<endl ;
getch();
return 0 ;
}
but it also gives the same error
what does while(value) mean then if value is a number like 56?
The point is that if z changes during the body of the loop, then when while (z % 10) is evaluated, it may now evaluate to false, depending on how z has changed. If z % 10 evaluates to 0 for the new value of z, then that's equivalent to it evaluating to false, and so the loop will end.