Logical error in -ve number

in the following program I only want the concept from U that what should i do so plz don't correct the code by ur-self I want to do it my self.in the following code when i am saying C++ that if a user enter number <= 0 again take the in-put from the users by returning back to main it gives logcal errors. for example i tried it like

return (i);

I got error. after that i said to it

cout<<"Enter the number again : " <<endl;
cin>>i;

again i got the error " I am not made to calculate below 0" even though number i entered was +ve.I don't want to use "break" word any were in my code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//Taking input from user & making cube via function.
#include <iostream>
using namespace std;
int multiplyfunc (int i)
{
    int wapis;
    if (i <= 0)

//added  cout with purpose to get value from user again to process via cin. but logical error

    cout<<" I am not made to calcule below 0 : \n";
    cin>>i;
    wapis = i*i*i;
    return (wapis);
}

int main()
{
    int i ;
    cout<<"Enter the number please = "<<endl;
    cin>>i;
    multiplyfunc(i);
    cout<<"Multiplication done in function & answer back in main "<<multiplyfunc(i)<<endl;
    system ("Pause");
    return 0;
}
now only line 11 belongs to the if. use {} to have several statements in the if.
Topic archived. No new replies allowed.