dipesh
always return 0
I think This is true when we don't have a output or return value.
dipesh
So we use void function if return value is not need or if we just want work to be done like displaying but if we need value or result after calculation we use int function and return value
dipesh
??
Anonymous
cout << "error: " << "bla bla";
Talula
So we use void function if return value is not need or if we just want work to be done like displaying but if we need value or result after calculation we use int function and return value
Yes, void function mean the function will not return any value, but int or char or byte or whatever returns a value, which is expected by the calling function.
dipesh
Thanks a lot Tazz!!
klimi
you should have asked proper question insted of asking "did anyone use GTK" ofc people did....
@Infolinux 🖖🏻
Hi
@Infolinux 🖖🏻
int main() { int VarCod, VarTipo,VarX,VarY,VarZ; float VarPCompra,VarIPI; printf ("INFORME O VALOR DE COMPRA - R$: "); scanf ("%f", &VarPCompra); VarX = 10; VarIPI = VarPCompra * (VarX/100); printf("Valor IPI..: %10.2f\n", VarIPI); } Result: INFORME O VALOR DE COMPRA - R$: 5 Valor IPI..: 0.00
@Infolinux 🖖🏻
VarIPI = VarPCompra * (VarX/100); Why doesn't this work?
@Infolinux 🖖🏻
Any idea?
Anonymous
VarIPI = VarPCompra * (VarX/100); Why doesn't this work?
VarX/100 is 0 because VarX is an integer. Try this instead VarIPI = (VarPCompra * VarX)/100
@Infolinux 🖖🏻
I'm going to change the variable type to Float
@Infolinux 🖖🏻
Perfect!
@Infolinux 🖖🏻
Result
Anonymous
I'm going to change the variable type to Float
You dont have to change the variable type of VarX as VarPCompra is already a float.
@Infolinux 🖖🏻
INFORME O VALOR DE COMPRA - R$: 5 Valor IPI..: 0.50
@Infolinux 🖖🏻
float VarPCompra,VarX,VarIPI;
@Infolinux 🖖🏻
---------- VarX = 10; VarIPI = VarPCompra * (VarX/100); printf("Valor IPI..: %10.2f\n", VarIPI); ----------
@Infolinux 🖖🏻
Result: INFORME O VALOR DE COMPRA - R$: 5 Valor IPI..: 0.50
@Infolinux 🖖🏻
Thanks… 👍🏻👍🏻👍🏻
佳辉
#include <stdio.h> float add(float , float); float sub(float , float); float mult(float , float); float div(float , float); float add(float num1, float num2) { return num1+num2; } float sub(float num1, float num2) { return num1-num2; } float mult(float num1, float num2) { return num1*num2; } float div(float num1, float num2) { return num1/num2; } int main() { float num1,num2,result; char choice; do { printf("1.Addition\n"); printf("2.Subtraction\n"); printf("3.Multiplication\n"); printf("4.Division\n"); printf("5.Exit\n\n"); printf("Enter Your Choice : "); scanf("%d",&choice); switch(choice) { case 1: printf("Enter first number : "); scanf("%f",&num1); printf("Enter second number : "); scanf("%f",&num2); result = add(num1,num2); printf("Result:%f",result); break; case 2: printf("Enter first number : "); scanf("%f",&num1); printf("Enter second number : "); scanf("%f",&num2); result = sub(num1,num2); printf("Result:%f",result); break; case 3: printf("Enter first number : "); scanf("%f",&num1); printf("Enter second number : "); scanf("%f",&num2); result = mult(num1,num2); printf("Result:%f",result); break; case 4: printf("Enter first number : "); scanf("%f",&num1); printf("Enter second number : "); scanf("%f",&num2); result = div(num1,num2); printf("Result:%f",result); break; case 5: return 0; break; default: printf("Wrong Choice..!!"); } printf("\n------------------------------------\n"); } while(choice<=5); }
佳辉
this is my coding for simple calculator
佳辉
At the choice there,if a enter a letter,the ouput become weird
佳辉
I wish the output can print out wrong choice when i enter a letter,can someone help me pls😭
Anonymous
I wish the output can print out wrong choice when i enter a letter,can someone help me pls😭
https://stackoverflow.com/questions/26583717/how-to-scanf-only-integer#26583787
@𝑺𝒐𝒃𝒌𝒂
Anonymous
Hello.everyone Pleas how we do an array of structure in C
Anonymous
Anonymous
*please
vector at C++ std
Anonymous
vector at C++ std
No i instead want to do it in C
Anonymous
I want to learn friends
Anonymous
I am a beginner
Anonymous
No i instead want to do it in C
https://stackoverflow.com/questions/19613752/how-to-properly-malloc-for-array-of-struct-in-c
@𝑺𝒐𝒃𝒌𝒂
佳辉
Test it
Also same😢
佳辉
Test it
Now my choice surpose is enter number from 1 to 5,but i hope when i enter a letter,it can print out wrong choice
@𝑺𝒐𝒃𝒌𝒂
Also same😢
What is your input?
佳辉
But i have no idea about it
@𝑺𝒐𝒃𝒌𝒂
In choice..
@𝑺𝒐𝒃𝒌𝒂
But i have no idea about it
If you want to use character, you must use something like A for addition, S for Subtraction, and so one. Then use a sentinel to break the loop.
@𝑺𝒐𝒃𝒌𝒂
Now my choice surpose is enter number from 1 to 5,but i hope when i enter a letter,it can print out wrong choice
Or you can us isdigit(h) from "ctype.h" library to make sure the user enter the properly value (a letter for example)
@𝑺𝒐𝒃𝒌𝒂
Or you can us isdigit(h) from "ctype.h" library to make sure the user enter the properly value (a letter for example)
Sorry. I want to say that 👇 Or you can use isdigit(h) from "ctype.h" library to make sure the user enter the properly value.
Sabyasachi
#include <stdio.h> #include <stdlib.h> struct node { int data; struct node*next; }*head=NULL; void insert(int x) { struct node* new=(struct node*)malloc(sizeof(struct node)); new->data=x; new->next=NULL; struct node* ptr=head; if(ptr==NULL) { ptr=new; head=new; } else { while(ptr->next!=NULL) ptr=ptr->next; ptr->next=new; } } void disp(struct node* start) { struct node* ptr=start; if(ptr==NULL) printf("Head Node is empty"); else { while(ptr!=NULL) { printf("%d->",ptr->data); ptr=ptr->next; } } } struct node* rotate() { struct node* ptr=head; struct node* prev=NULL; struct node* nex=NULL; while(ptr!=NULL); { nex=ptr->next; prev=ptr; ptr=nex; nex->next=prev; } return(prev); } int main () { int k, x; printf ("Enter the number of node"); scanf ("%d", &k); for (int i = 1; i <= k; i++) { printf ("Enter the data for nodes"); scanf ("%d", &x); insert(x); } disp(head); head=rotate(); disp(head); return(0); }
Sabyasachi
Please see where am I going wrong?
Sabyasachi
It's continuously taking inputs
Владислав🇺🇦
Hello. I am working on a terminal program that (as I imagine it) is intended to handle keyboard input. I wish it to be cross-platform so I decided to use third-party library. I chose OIS(Object oriented Input System), but it needs a window handle to provide keyboard input handling. So I have two questions: Is there a way to get that handle of a terminal window via C++ code (and/or X11 but it means I will use platform-specific code either way)? Maybe I should consider other ways of handling input? The most obvious ways to resolve this problem I am thinking of are to choose another library (but there are not many of them) or use platform-specific code for each platform. Any advice is much appreciated!
Golden Age Of
Ok, hi everyone, i need someone's help in one interesting question, really appreciate your help. Here i have a function which locally inside allocates some memory and creates an object, then it's dereferenced and returned to the list by push_back(), here is the question - do i need to free the memory i allocated in function? I ask it cause when i debug run it, there is called only one destructor of my class and it's list destructor, but in the list i have some quantity of objects. If my function returns Some_Class* , i dereference it and push into the list, do i push there the copy of the object and i've memory leak or i push that object i created in function ?
Sabyasachi
Yrs
Sabyasachi
It is working fine with two display function. Whenever I am using rotate function it is making problem
Golden Age Of
Not me
Sabyasachi
What rotate should do?
Rotate will rotate the linked list
Anonymous
Not me
Sorry
Anonymous
Anyone know about programming with OpenGL or Magnum C++ Framework? I need to learn how to move my camera in 3D instead of simply rotating my 3D polygon itself Specifically instead of a rotating cube, i want to learn how to make a movable camera Simple movement such as panning (up down left right) and zooming (forward, backward) Will suffice I am NOT looking for complete code
Anonymous
Rotate will rotate the linked list
Your logic for reversing the list is wrong
Sabyasachi
Golden Age Of
also you have variables named *new*, how does it work? what is your IDE and compiler?
Anonymous
Pls tell me the correct one
Instead of just taking two nodes prev and nex, you should take 3 nodes into account like prev, nex and nex_nex
Anonymous
Anonymous
Eg ITTERATE the list accepting values into each node, until NULL is reached
Sabyasachi
Your rotate goes into an infinite loop
But the first display function in main is befor the rotate one