ɛ n h ᴀ n c ɛ ґ 🧟‍♂️
Does the problem have any any other lines of code?
Like maybe it performs some task in the beginning then the user has to enter “000” to close it
Anonymous
Anyway i did it thank you
shriman_deepak
#include <iostream> using namespace std; int main() { int x; float y; cin>>x>>y; if ((x%5==0)&&(y>x+0.5)) { cout<<y-x+0.5; } else cout<<y; return 0; }
shriman_deepak
Pooja would like to withdraw X $US from an ATM. The cash machine will only accept the transaction if X is a multiple of 5, and Pooja's account balance has enough cash to perform the withdrawal transaction (including bank charges). For each successful withdrawal the bank charges 0.50 $US. Calculate Pooja's account balance after an attempted transaction.
shriman_deepak
for this question why i am not getting right tick in codechef ?
shriman_deepak
No no
shriman_deepak
In vs code it's running fine but on codechef it shows wrong
shriman_deepak
Tried this too 😅
shriman_deepak
Pavel
U use codechef ?
No, I don't
Lucas
Hi everyone. I'm trying to create a struct that stores a dynamically allocated 2D matrix in a variable and its dimensions This is what I tried: typedef struct mat_type{ double ** m; int tamx, tamy; } mat_type; `` void createMatrix(mat_type * mat, int tx, int ty){ mat->m = (double **) malloc(tx*sizeof(double*)); for (int i=0; i<tx; i++){ mat->m[i] = (double*) malloc(ty*sizeof(double)); for (int j=0; j<ty; j++){ mat->m[i][j] = 0.0; } } mat->tamx = tx; mat->tamy = ty; } `` mat_type * matrixTest; createMatrix(matrixTest, 5, 5); I'm getting segfault.
Lucas
You haven't malloced for the matrixTest pointer.
Can't I just alloc memory for the matrixTest->m ?
olli
Thanks. This worked but when I print the matrix, I get random numbers instead of 0.0
How do you print them? seems to work https://godbolt.org/z/987noM764
Lucas
How do you print them? seems to work https://godbolt.org/z/987noM764
I can't thank you enough! Turns out I was using -> and it's wrong, I'm gonna study these things more. Thank you
mayway
How to debug in vscode
Blaeq
The option there
Ибраги́м
https://www.youtube.com/watch?v=A8nNjpaiP5M
𝐈𝐧𝐯𝐢𝐧𝐜𝐢𝐛𝐥𝐞𝟎𝟎𝟏🌝
I am beginner a beginner in coding actually. I want to learn the basics first of c language..anyone can suggest me the material or channel to which I have to follow for the same?🙂
𝐈𝐧𝐯𝐢𝐧𝐜𝐢𝐛𝐥𝐞𝟎𝟎𝟏🌝
Jasur Fozilov 🐳
https://pastebin.com/JFs32XBG can anyone explain me double (*)(double,double) in map ?
Anonymous
https://pastebin.com/JFs32XBG can anyone explain me double (*)(double,double) in map ?
It is a function pointer to functions that have two 'double' parameters and returns a double
_dvd
Hi. Does anyone know an example of an ubjson parser written in cpp?
_dvd
https://github.com/nlohmann/json
thank you, but I was looking for ubjson, which is slightly different
Anonymous
thank you, but I was looking for ubjson, which is slightly different
Did you look at the link? The readme . md file suggests that it supports bson, ubjson,message pack and cbor formats as well. I know what Ubjson is
_dvd
I'm sorry, I didn't read it
Nank
Hello i'm stuck here
Nank
#include"Etudiants.h" #include <stdio.h> #include <stdlib.h> //enter the data of a student Student readStudent(){ Student E; printf("Name : "); scanf("%s", E.name); printf("Surname : "); scanf("%s", E.surname); printf("Identifiant : "); scanf("%s", E.username); printf("Notes cc : "); scanf("%d", &E.scoreCc); printf("Notes Ex : "); scanf("%d", &E.scoreEx); printf("\n"); return E; } //read the data of a student void printStudent(Student E){ printf("Name : %s \tSurname : %s\tusername : %s\tscoreCc : %d\tscoreEx : %d", E.name, E.surname, E.username, E.scoreCc, E.scoreEx); printf("\n"); } //enter the data of 10 students in a table Student readTabStudent(){ Student E; for(int i = 0; i < 2; i++) readStudent(); return E; } //read the data of 10 students in a table void printTabStudent(Student E){ for(int i = 0; i < 2; i++) printStudent(E); }
Nank
when i enter informations for two students, it doesn't return those informations.
Nank
This is what i get after execution Name : Ngo Surname : Jule Username : ML250 ScoreCC: 12 ScoreEx: 12 Name : Ngameni Surname :Mariam Username : PL550 ScoreCC: 14 ScoreEx: 10 Name : Surname : @ Username : ScoreCC : 1254125 ScoreEx : 0 Name : Surname : @ Username : ScoreCC : 1254125 ScoreEx : 0
Nank
Can anybody tell me why?
Nank
This is how i've defined Student
Nank
typedef struct{ char name[10]; char surname[10]; char username[10]; int scoreCc; int scoreEx; }Student;
Jacky
all right, why don’t you use the structure pointer for parameter?
Jacky
the func readStudent, u can change the retVal for input values by the pointer of structure student
Nank
all right, why don’t you use the structure pointer for parameter?
I didn't know i have to use pointer. I don't know this notion yet Isn't there an alternative way ?
Jacky
the retVal of stacked variable when it returned, all will be destroyed
Jacky
u need to promise the lifetime of retVal, then u can get the result
Jacky
correctly
Spirit
question about try/catch and handling exceptions with concerns about memory management
Spirit
class A { public: A() { try { b = new B(); } catch (std::bad_alloc) { cerr << "Couldn't create b.\n"; } }; ~A(); }; class B { public: B() { try { c = new C(); throw(bad_alloc()); } catch (std::bad_alloc) { cerr << "Couldn't create c.\n"; throw(std::bad_alloc()); } }; ~B(); C *c; }; int main() { A *a = new A(); return 0; };
Spirit
do i have to manually delete b or c ? Will this cause a memory leak?
Anonymous
do i have to manually delete b or c ? Will this cause a memory leak?
You should delete both b and c. If you don't, it will lead to a memory leak.
Spirit
so throing from the constructor won't automatically free the object or memory of objects allocated in the constructor before the exception was thrown.
Anonymous
so throing from the constructor won't automatically free the object or memory of objects allocated in the constructor before the exception was thrown.
It will free up space allocated for local variables inside the constructor and it will also destroy the class members. But you are responsible for any heap allocations that you make. That is why you should either use RAII or use smart pointers.
Spirit
okay, i just started reading about RAII today trying to understand it.
Spirit
is there a down side to smart pointers.
Anonymous
is there a down side to smart pointers.
Well there are a few but benefits outweigh the cost.
Spirit
i see thank you
Ludovic 'Archivist'
is there a down side to smart pointers.
The main downside is are a slight codesize and a slight overhead if you are in a context that allows exceptions
Anonymous
The main downside is are a slight codesize and a slight overhead if you are in a context that allows exceptions
A few othersas well like when you use make_shared along with weak pointers, then the memory pointed to by the shared_pointers may not be freed even if they all go out of scope as long as a weak_ptr is still present. If it is freed, then your implementation's make_shared is not an efficient implementation.
Anonymous
Just started learning c and c++
Anonymous
The data is freed when all shared_ptr are gone. The control block is freed when all weak and shared_ptr are gone
When you use make_shared, implementations are allowed to allocate the control block and data at the same time using one call for efficiency purposes. When they do this, they can't free them at different times. So data is freed along with control block. If an implementation of make_shared uses separate calls to allocate memory for control block and data then there is an efficiency issue which is what I said in my last post.
Nank
all right, why don’t you use the structure pointer for parameter?
I don't unterstand please Can you explain a bit simply?
Shubh
#include <stdio.h> #include <conio.h> #include <string.h> struct date { int d,m,y; }; struct student { char name[50]; int rollno; char divi[50]; float marks; char mobile_no[50]; }; struct st2 { char name2[40]; int rollno_1; char divi_1[40]; float marks_1; char mobile_no_1[40]; }; struct date_1 { int d,m,y; }; int main () { struct student s; printf ("Enter the first student information: "); printf ("\nEnter the name of the student: "); scanf ("%[^\n]",s.name); printf ("Enter the roll numner of the student: "); scanf ("%d",&s.rollno); printf ("Enter the division of the student: "); scanf ("%s",s.divi); printf ("Enter the marks of the student: "); scanf ("%f",&s.marks); printf ("Enter the mobile number of the student: "); scanf ("%s",s.mobile_no); struct date d; printf ("enter the student Date Of Birth: \n"); printf ("DAY: "); scanf ("%d",&d.d); printf ("MONTH: "); scanf ("%d",&d.m); printf ("YEAR: "); scanf ("%d",&d.y); printf ("----------[%s] racord----------\n",s.name); printf ("| student name is: %s\n",s.name); printf ("| student roll no is: %d\n",s.rollno); printf ("| student division is: %s\n",s.divi); printf ("| student marks is: %f\n",s.marks); printf ("| student nmobile number is: %s\n",s.mobile_no); printf ("| student birth date is: %d/%d/%d\n",d.d,d.m,d.y); struct st2 f; printf ("Enter the Second student information: \n"); printf ("Enter the name of the student: \n"); scanf ("%[^\n]",f.name2); printf ("Enter the roll number of the student: "); scanf ("%d",&f.rollno_1); printf ("Enter the division of the student: "); scanf ("%s",f.divi_1); printf ("Enter the marks of the student: "); scanf ("%f",&f.marks_1); printf ("Enter the mobile number of the student: "); scanf ("%s",f.mobile_no_1); struct date_1 b; printf ("enter the student Date Of Birth: \n"); printf ("DAY: "); scanf ("%d",&b.d); printf ("MONTH: "); scanf ("%d",&b.m); printf ("YEAR: "); scanf ("%d",&b.y); printf ("----------[] racord----------\n"); printf ("| student name is: %s\n",f.name2); printf ("| student roll no is: %d\n",f.rollno_1); printf ("| student division is: %s\n",f.divi_1); printf ("| student marks is: %f\n",f.marks_1); printf ("| student nmobile number is: %s\n",f.mobile_no_1); printf ("| student birth date is: %d/%d/%d",b.d,b.m,b.y); return 0; }
Shubh
#include <stdio.h> #include <conio.h> #include <string.h> struct date { int d,m,y; }; struct student { char name[50]; int rollno; char divi[50]; float marks; char mobile_no[50]; }; struct st2 { char name2[40]; int rollno_1; char divi_1[40]; float marks_1; char mobile_no_1[40]; }; struct date_1 { int d,m,y; }; int main () { struct student s; printf ("Enter the first student information: "); printf ("\nEnter the name of the student: "); scanf ("%[^\n]",s.name); printf ("Enter the roll numner of the student: "); scanf ("%d",&s.rollno); printf ("Enter the division of the student: "); scanf ("%s",s.divi); printf ("Enter the marks of the student: "); scanf ("%f",&s.marks); printf ("Enter the mobile number of the student: "); scanf ("%s",s.mobile_no); struct date d; printf ("enter the student Date Of Birth: \n"); printf ("DAY: "); scanf ("%d",&d.d); printf ("MONTH: "); scanf ("%d",&d.m); printf ("YEAR: "); scanf ("%d",&d.y); printf ("----------[%s] racord----------\n",s.name); printf ("| student name is: %s\n",s.name); printf ("| student roll no is: %d\n",s.rollno); printf ("| student division is: %s\n",s.divi); printf ("| student marks is: %f\n",s.marks); printf ("| student nmobile number is: %s\n",s.mobile_no); printf ("| student birth date is: %d/%d/%d\n",d.d,d.m,d.y); struct st2 f; printf ("Enter the Second student information: \n"); printf ("Enter the name of the student: \n"); scanf ("%[^\n]",f.name2); printf ("Enter the roll number of the student: "); scanf ("%d",&f.rollno_1); printf ("Enter the division of the student: "); scanf ("%s",f.divi_1); printf ("Enter the marks of the student: "); scanf ("%f",&f.marks_1); printf ("Enter the mobile number of the student: "); scanf ("%s",f.mobile_no_1); struct date_1 b; printf ("enter the student Date Of Birth: \n"); printf ("DAY: "); scanf ("%d",&b.d); printf ("MONTH: "); scanf ("%d",&b.m); printf ("YEAR: "); scanf ("%d",&b.y); printf ("----------[] racord----------\n"); printf ("| student name is: %s\n",f.name2); printf ("| student roll no is: %d\n",f.rollno_1); printf ("| student division is: %s\n",f.divi_1); printf ("| student marks is: %f\n",f.marks_1); printf ("| student nmobile number is: %s\n",f.mobile_no_1); printf ("| student birth date is: %d/%d/%d",b.d,b.m,b.y); return 0; }
what is the problem of the skip st2 name skip
Shubh
st2 skip direct jump to roll no
Jacky
func readTabStudent, variable E is not initiated, so that it’s randomly
Jacky
I don't unterstand please Can you explain a bit simply?
the other question is the func only use ones variable, but u want to use for loop
Jacky
jni?
Jacky
or implement with C
Anonymous
What are derived data types in c++.... I could not understand from GFG.
Jacky
what is GFG
Anshul
What are derived data types in c++.... I could not understand from GFG.
There are two types of data types. One is primitive one that are keywords known by compiler and other are user defined or derived. If you have a data that is number or char or bool you can use primitive data types but for any other type of information you need to derive your own data types. Let's say you want to store list of characters then you can use array, it's a derived data type. Or you want to store information about a student like his age,name,address, mobile number then you can create a class or structure and define these properties for your student. And it'll be a derived data type
Anshul
what is GFG
I think he meant geeks for geeks
Snnr
/notes
Shubh
/notes
Jacky
/get best-book
Shubh
/get
Shubh
#include <stdio.h> #include <conio.h> #include <string.h> struct date { int d,m,y; }; struct student { char name[50]; int rollno; char divi[50]; float marks; char mobile_no[50]; }; struct st2 { char name2[40]; int rollno_1; char divi_1[40]; float marks_1; char mobile_no_1[40]; }; struct date_1 { int d,m,y; }; int main () { struct student s; printf ("Enter the first student information: "); printf ("\nEnter the name of the student: "); scanf ("%[^\n]",s.name); printf ("Enter the roll numner of the student: "); scanf ("%d",&s.rollno); printf ("Enter the division of the student: "); scanf ("%s",s.divi); printf ("Enter the marks of the student: "); scanf ("%f",&s.marks); printf ("Enter the mobile number of the student: "); scanf ("%s",s.mobile_no); struct date d; printf ("enter the student Date Of Birth: \n"); printf ("DAY: "); scanf ("%d",&d.d); printf ("MONTH: "); scanf ("%d",&d.m); printf ("YEAR: "); scanf ("%d",&d.y); printf ("----------[%s] racord----------\n",s.name); printf ("| student name is: %s\n",s.name); printf ("| student roll no is: %d\n",s.rollno); printf ("| student division is: %s\n",s.divi); printf ("| student marks is: %f\n",s.marks); printf ("| student nmobile number is: %s\n",s.mobile_no); printf ("| student birth date is: %d/%d/%d\n",d.d,d.m,d.y); struct st2 f; printf ("Enter the Second student information: \n"); printf ("Enter the name of the student: \n"); scanf ("%[^\n]",f.name2); printf ("Enter the roll number of the student: "); scanf ("%d",&f.rollno_1); printf ("Enter the division of the student: "); scanf ("%s",f.divi_1); printf ("Enter the marks of the student: "); scanf ("%f",&f.marks_1); printf ("Enter the mobile number of the student: "); scanf ("%s",f.mobile_no_1); struct date_1 b; printf ("enter the student Date Of Birth: \n"); printf ("DAY: "); scanf ("%d",&b.d); printf ("MONTH: "); scanf ("%d",&b.m); printf ("YEAR: "); scanf ("%d",&b.y); printf ("----------[] racord----------\n"); printf ("| student name is: %s\n",f.name2); printf ("| student roll no is: %d\n",f.rollno_1); printf ("| student division is: %s\n",f.divi_1); printf ("| student marks is: %f\n",f.marks_1); printf ("| student nmobile number is: %s\n",f.mobile_no_1); printf ("| student birth date is: %d/%d/%d",b.d,b.m,b.y); return 0; }
please solution this program,