Trying to use doubles in C++. Not sure where I'm going wrong -
so i'm writing program takes input , tries input 1 either dividing 2 if it's even, or multiplying 3 , adding 1. it's giving me error when try compile it:
bigbeno37@vm-0:~/github2$ g++ numbergenerator1.cpp numbergenerator1.cpp:1:2: warning: #import deprecated gcc extension [-wdeprecated] numbergenerator1.cpp: in function ‘int main()’: numbergenerator1.cpp:13:5: error: ‘inputnumberclone’ not declared in scope numbergenerator1.cpp:16:26: error: invalid operands of types ‘double’ , ‘int’ binary ‘operator%’ numbergenerator1.cpp:19:26: error: cannot convert ‘int(int (*)(void*), void*, int, void*, ...)throw ()’ ‘double’ in assignment numbergenerator1.cpp:24:26: error: cannot convert ‘int(int (*)(void*), void*, int, void*, ...)throw ()’ ‘double’ in assignment
this code
#import <iostream> using namespace std; int main(){ cout << "please enter number: " << endl; double inputnumber = 0; double inputernumberclone = 0; double stepsclone = 0; cin >> inputnumber; inputnumberclone = inputnumber; for(double steps = 0; inputnumber != 1; steps++){ if(inputnumber % 2 == 0){ inputnumber = inputnumber / 2; stepsclone = clone; }else{ inputnumber = inputnumber * 3; inputnumber++; stepsclone = clone; } } cout << "it takes " << stepsclone << " 1 " << inputnumberclone << endl; return 0; }
can me out?
#include
not#import
.- you wrote
inputernumberclone
instead ofinputnumberclone
. - you have use
fmod
double
s instead of%
.
Comments
Post a Comment