Viprr
Book
@𝑺𝒐𝒃𝒌𝒂
Book
#cbook
Yasas
Can somebody help me? I wrote a c++ program which was like a calculator. I compiled it and it worked fine on my laptop. But when I try to execute it on another computer it doesn't work. Why does this happen?
Pavel
Can somebody help me? I wrote a c++ program which was like a calculator. I compiled it and it worked fine on my laptop. But when I try to execute it on another computer it doesn't work. Why does this happen?
Can you share the code of the program? Also can you describe what "doesn't work" means in this case? Does it crash immediately? Or print something before crash?
dipesh
hey
dipesh
myPow(double x, int n) while making this power user defined function how can i get result for negative power coefficient
dipesh
double myPow(double x, int n){ int i; float ans=1; if(n==0) { return 1; } else { for(i=1;i<=n;i++) { ans=(float)ans*x; } return ans; } }
Anonymous
double myPow(double x, int n){ int i; float ans=1; if(n==0) { return 1; } else { for(i=1;i<=n;i++) { ans=(float)ans*x; } return ans; } }
Just fixing your code assuming it works: double myPow(double x, int n){ float ans=1; if(n==0) { return 1; } else { for(int i=1;i<=abs(n);i++) { ans=(float)ans*x; } return (n>0)?ans:(1/ans); } }
dipesh
great . thanks a lot
Anonymous
Btw ans should be a double variable and get rid of the casts to float
Anonymous
dipesh
Are you that lazy?
im still getting the wrong result thats way
dipesh
for 2 to the power -2 im still getting 1 instead of 0.25
dipesh
#include<stdio.h> double myPow(double x, int n); int main() { float x,ans; int n; scanf("%f",&x); scanf("%d",&n); ans=myPow( x, n); printf("%f",ans); } double myPow(double x, int n){ int i; float ans=1; if(n==0) { return 1; } else { for(i=1;i<=n;i++) { ans=(float)ans*x; } return (n>0)?ans:(1/ans); } }
dipesh
what does that abs(n) means
Anonymous
what does that abs(n) means
https://en.cppreference.com/w/cpp/numeric/math/abs Ignore the std:: namespace stuff. The function meaning is otherwise same in both C and C++
dipesh
i didnt got it i am just learning c and dont know much abbout c++\
Anonymous
return (n>0)?ans:(1/ans); use float(1/ans)
Anonymous
i didnt got it i am just learning c and dont know much abbout c++\
Abs is a function that returns the absolute value of a number. If a number is positive then its absolute value is the same. If a number n is negative then its absolute value is -n
ninja
abs(n) == |n|
Anonymous
return (n>0)?ans:(1/ans); use float(1/ans)
No. Ans is already a float (should have been a double). So 1/ans will also be a float even without the cast.
Anonymous
got it
🅸🅼🆁🅰🅽
C is legendary
Ravi
1 3 4 5 9
Anonymous
1 3 4 5 9
1 and 4 dont
Ravi
1 and 4 dont
sorry sorry thats true 😅
Anonymous
Cant you do it yourself or try it on your own system? What is the point of questions like this?
tumaini
C++ line to limiti, the number of digits for a number to be entered by a user Help, please🙏
255mufasa
which stuffs are you guys using in studying c++
255mufasa
i dont understand it cleary
255mufasa
i just see stars😞
Anonymous
/get cbook
255mufasa
thank you👍
NAM3L3SS
#include <iostream> Using namespace std; int main() { String name; Cout<<"Enter the name:"<<endl; Cin>>name; While(name<5) { Cout<<name; name++; } return 0; }
NAM3L3SS
Hey fam am trying to loop a name from the user 4times
NAM3L3SS
Any help
Ravi
take a variable other than name which will be int to store the count of loops
tumaini
#include<iostream> Using namespace std; Int main() { int salary;int number; Salary=1000000; Court<<"Enter your credit card number" \n; Cin>>number; If(condition) { Cout<<" Your net salary is "<<salary<<endl; Cout<<"After VAT deduction your base salary is"<<salary*0.2<<endl; } else Cout<<" your credit card number is wrong"; return 0; } //Please help me with the condition that can limit number to have any 13 digits using if condition//
Anonymous
Hello
Anonymous
Hello please who can help me to write a code c for humanoide robot with arduino 😔🙏🙏
Anonymous
I want to move as much as possible and even walk
Anonymous
Hello brother can anyone say my codebits correct or not ❓
•‿•
#include <stdio.h> int main() { int a, b; b = -3 --(-3); printf("b =%d ", b); return 0; }
•‿•
why this show error
•‿•
where?
Ravi
-3-(-(-3))
Ravi
like this
JY
-3 -4 missing operator
JY
Two numbers
JY
-3 - --(-3) will work
Anonymous
#include<iostream> Using namespace std; Int main() { int salary;int number; Salary=1000000; Court<<"Enter your credit card number" \n; Cin>>number; If(condition) { Cout<<" Your net salary is "<<salary<<endl; Cout<<"After VAT deduction your base salary is"<<salary*0.2<<endl; } else Cout<<" your credit card number is wrong"; return 0; } //Please help me with the condition that can limit number to have any 13 digits using if condition//
Your credit card number is 13 digit long. They cant be stored in an int. You need a unsigned long long. In production code, credit card numbers are stored in a byte array and are then encrypted and the array used for getting the input is zeroed out. Anyway for your use case, you can store them in a string and then check the length and see if it is 13 characters long. If it is not you then flag an error. If it is 13 characters long, then you can convert the string to an unsigned long long using stoull and then see if all the 13 characters were converted. If not you flag an error.
Anonymous
•‿•
-3-(-(-3))
b = -3 --(-3);
Anonymous
why this show error
It shows an error because the pre decrement operator requires an lvalue but -3 is a rvalue
•‿•
here is - - - subtraction sign
•‿•
•‿•
here is - - - subtraction sign
so how to use pre decrement operator in that ?
Anonymous
so how to use pre decrement operator in that ?
You cant use it on rvalues. You can use it only on lvalues like for example a variable
•‿•
oh understand
•‿•
hey can you suggest me where to practice c programming question
•‿•
i want to practice
JY
Compiler should figure it out. From user perspective, what is difference? It should use a temp var for -3. User intention is clear
Anonymous
Compiler should figure it out. From user perspective, what is difference? It should use a temp var for -3. User intention is clear
That is not how the standard/compiler works. They dont presume to understand what you meant unless you specify it clearly following the rules laid out in the language's grammar.
JY
Does (-3)-- work?
•‿•
Does (-3)-- work?
i don't think it work it also not work
JY
Does (-3)-- work in python for example
Anonymous
Does (-3)-- work?
The post decrement also requires an lvalue. The difference with predecrement is that predecrement returns an lvalue while post decrement returns an rvalue.
Hanz
Because you havent assign anything to comp
Pavel
comp == is not assignment, should be one =
Hanz
Change all == to = in your first three if nodes in main