▪️fateme👷🏻‍♀️
Why without using return?
I know how to solve it with return I'm in search for a new way to solve it
Pavel
I know how to solve it with return I'm in search for a new way to solve it
Ok, so if you don't want to return from your function, then you need to replace the return type with void, and then you can't use it in the assignment.
Pavel
I want the printf operation take place in main() function
You can just move it there, your you use the same variable name with the global variable, so it should just work
Pavel
You can just move it there, your you use the same variable name with the global variable, so it should just work
or wait, global variable was in some another code snippet, but anyway you have the same name for that array in main
Pavel
#include<stdio.h> void max(int arr[], int n) { int i; for(i=0;i<n;i++) { arr[i]=arr[i]+1; } } int main() { int arr[7]={1,22,5,43,6,42,6}; int n=7; max(arr,n); int i; for(i=0;i<n;i++) { printf("%d ",arr[i]); } }
DaviChan
Well somehow there is always a way 😂. But no, it is not supported by default, only overloading the usual operators is
Pavel
You can overload operator[] for your class. It is done for a lot of STL containers https://en.cppreference.com/w/cpp/language/operators
Anonymous
char CNames[128]; int NumCurr = 0; int ccyIdx(char* name) { char Ccy[4]; memcpy(Ccy,name,4); Ccy[3] = 0; for(int n=0; n<32; n++) { if(!CNames[n*4]) { // not yet stored strcpy(CNames+n*4,Ccy); NumCurr++; return n; } if(strstr(CNames+n*4,Ccy)) return n; } return 0; } In the code above: Regarding if(!CNames[n*4]) What is the logic? If CNames[n*4] is not what? What am I missing?
Pavel
What do you mean by custom operator, like £ operator? :) No, unfortunately it's not possible, you are right
Pavel
char CNames[128]; int NumCurr = 0; int ccyIdx(char* name) { char Ccy[4]; memcpy(Ccy,name,4); Ccy[3] = 0; for(int n=0; n<32; n++) { if(!CNames[n*4]) { // not yet stored strcpy(CNames+n*4,Ccy); NumCurr++; return n; } if(strstr(CNames+n*4,Ccy)) return n; } return 0; } In the code above: Regarding if(!CNames[n*4]) What is the logic? If CNames[n*4] is not what? What am I missing?
Numbers can be implicitly or explicitly converted to bool int a = 6; bool b = a; The value of the resulting bool will be false only if the value of the integer was zero. In all other cases it will be true. So this if (!CNames[n*4]) Is equivalent to this if(CNames[n*4] == 0)
Pavel
Are you saying that, if nothing is stored in CNames[128], then each element inside the array of CNames has the value of 0?
If the element by that index is zero, usually that means end of c-string, or empty space after a c-string in a buffer
Pavel
This code seem to iterate over chunks 4 byte each, not sure the exact logic
Anonymous
This code seem to iterate over chunks 4 byte each, not sure the exact logic
The goals is that, we have 32 words, and each word has 3 letters, and each word is an element. And every element needs a null terminator (so 32 ×4 =128). We are trying to give a number(index to each word)
Ольга
#include <iostream> #include <string> #include <sstream> using namespace std; struct person_str { int age; void input(); void print(); }; void person_str::print() { cout<< this->age << endl; } void person_str::input(person_str*) { person_str p; cout<<"Enter age: "; cin>>p.age; } int main() { person_str p; p.input(&p); p.print(); return 0; } Hello maybe someone can explain what I do not right. Because I can't understand how it is
Pavel
The goals is that, we have 32 words, and each word has 3 letters, and each word is an element. And every element needs a null terminator (so 32 ×4 =128). We are trying to give a number(index to each word)
Sounds reasonable, I guess this code checks for the first symbol in the 3 letters and checks if that's the null terminator (then the word is not filled yet)
Anonymous
Oh, I think you just made it clearer. Thank you so much
Ольга
But you mean input function?
Because I trying not to make a new variable but it don't work
Anupam2.7
Can we return more than one datatype in a defined function(in c++)? Because while defining a function we have to specify a datatype too and for eg if we specify int then we can not return char or string datatypes.
Anupam2.7
Does void() function return anything?
Anonymous
No
Pavel
Can we return more than one datatype in a defined function(in c++)? Because while defining a function we have to specify a datatype too and for eg if we specify int then we can not return char or string datatypes.
there are multiple ways to return two values: - pack them into a struct - pack them into a tuple - return second and more values through mutable reference arguments e.g. if we want to return an int and a float, we can have something like this struct: struct OurStruct { int val1; int val2; }; OurStruct ourFn() { ... OurStruct ourStruct; ourStruct.val1 = value1; ourStruct.val2 = value2; return ourStruct; } int main() { auto [value1, value2] = ourFn(); } tuple: std::tuple<int, float> ourFn() { ... return std::make_tuple(value1, value2); } int main() { auto [value1, value2] = ourFn(); } out parameter: int ourFn(float& outValue) { ... outValue = value2; return value1; } int main() { float value2; int value1 = ourFn(value2); }
PI cadaeibfe
How can i fix " error id returned 1 exit status"?
M__
does anyone do leetcode
PI cadaeibfe
#include <iostream> using namespace std; int main() { cout << "Hello"; return 0; } But returns (error id returned 1 exist status) how can i fix this error?
Strife
#include <iostream> using namespace std; int main() { cout << "Hello"; return 0; } But returns (error id returned 1 exist status) how can i fix this error?
I may guess, the old instance of your program is still running. Windows does not allow to change the files which are currently "in use" and your linker cannot write the new .exe on the top of the running one. Try stopping/killing your program.
Anonymous
CppCon 2022 @ Denver Schedule (Ongoing) https://lnkd.in/gFuauGb3 Watch the recorded videos at https://www.youtube.com/user/cppcon The Friday events were live streamed. Sorry about not sharing the link earlier.
Void
#include <stdio.h> int main() { int x,y,z; for(x=0;x<=100;x++) { for(y=0;y<=100;y++) { for(z=0;z<=100;z++) { if(5*x+3*y+z/3==100&&x+y+z==100&z%3==0); printf("%d,%d,%d",x,y,z); } } } return 0; }
Void
Guys what's wrong with my code
▪️fateme👷🏻‍♀️
#include<stdio.h> void max(int arr[], int n) { int i; for(i=0;i<n;i++) { arr[i]=arr[i]+1; } } int main() { int arr[7]={1,22,5,43,6,42,6}; int n=7; max(arr,n); int i; for(i=0;i<n;i++) { printf("%d ",arr[i]); } }
int max(); int main() { int arr[7]={1,22,5,43,6,42,6},i; int* result=(int*)malloc(sizeof(int)); for(i=0;i<7;i++) { *(result+i)=max((arr,7); } for(i=0;i<7;i++) { printf("%d\n",*(result+i)); } } int max(int* arr,int n) { int i; for(i=0;i<n;i++) { arr[i]=arr[i]+1; } } Why I can't achieve my desire through this method?
Your max function returns nothing here
And you can't return whole array
Ольга
https://onlinegdb.com/iwIfItEAD Hello! Maybe someone can tell me why this warning appears. Any help would be appreciated
▪️fateme👷🏻‍♀️
What is your desire? :)
I want whole array as output with everyone get +1 but it didn't work as my expectation I want to solve it without any return; I want to solve it with assigning dynamic memory
Ольга
Do you understand what that warning means?
Well, it seems that the function is defined to return a value, but I don't return anything with it. But I don't need to return any value, I just need to know if the check is valid or not. Or I mistaken?
Mohamed
hello
Mohamed
I am an Angular frontend developer. I would like to print data online without going through the browser to communicate with my network printer by specifying the printer's ip. Can someone help me with a script or guide me with a package because I don't know the system environment very well?
Ольга
Do you understand what that warning means?
I solved this error by adding another return at the end of the function, is this normal or wrong?
Гулящий
Hello. I have a hierarchy of classes, all deriving from one base. I want each of them to print a message upon creation. I don't want to call the printing method every time. https://godbolt.org/z/19dbhYj9Y Could you please help?
~
https://github.com/mustafakraizim98/Skyland-Coding-Challenge
Void
Guys can you check my code
Void
#include <stdio.h> #include <math.h> int main() { float t,p2; scanf("%f",&t); if(t<5) {p2=0;} else if(t=5) {p2=2; } else if(t>5) { t=(t-5)/5; t=ceil(t); p2=t*2; } printf("%.1f",p2); return 0; }
Void
When t=11,p2 should be 4 right?🤔
Void
BlAnk
Can someone provide me with an idea for a c++ project as i am a beginner for this and internet is providing way too complex ones . It would be helpful if this project actually helps me grow
BlAnk
Bank and hotel management, would I be able complete it within a month
Kanni
BlAnk
Yes even3 days is enough
Thanks i will try it and if i get good remarks i would be grateful
Ольга
https://onlinegdb.com/iwIfItEAD Hello! Maybe someone can tell me why this warning appears. Any help would be appreciated
Guys I realy trying to fix it but my solution didn't help. I hope someone will help
Pavel
Guys I realy trying to fix it but my solution didn't help. I hope someone will help
Share the fixed code, if you've fixed the problems that we told you about
Void
#include <stdio.h> #include <math.h> int main() { float x; int p; scanf("%f",&x); x=ceil(x); if(x<3) {p=10; } else if(3<x<=13) {p=10+2*(x-3); } else if(x>13) {p=10+2*(x-3)+3*(x-13); } printf("%d",p); return 0; }
Void
I think something is wrong but i can't find out😐
Ольга
I found on the Internet that this will help solve the problem (and there is no warning), but now the code does not work as it should
Aleksandr
is it possible to get random element from list?
Strife
Thanks its working now
you're welcome. To be honest, I just searched for your problem on the internet and found the answer. If you have any questions, you can ask them in the group. Certainly, people with a lot of experience can help you, but don't forget that the internet is the answer to all problems.