CALVIN
Is it possible to allow the user input a list of numbers in c++....... Without declaring how many numbers are to be on the list.......?
Melbgm
Hey guys , array = (int)malloc(sizeof(int) * n); --> The code gives me a warning. What should I do to avoid the warning?
coal
in any case, aren't you trying to cast it to an int*?
coal
even so, that has several problems
coal
its unnecessary because void * is automatically and safely promoted to any other pointer type
coal
it adds clutter, its redundant and in general bad code
Melbgm
Allright , thank you guys
Melbgm
I have a easy question , The user can enter as many numbers as they want, but there can be a maximum of 5 numbers, how can I limit this in the loop?
coal
I have a easy question , The user can enter as many numbers as they want, but there can be a maximum of 5 numbers, how can I limit this in the loop?
std::vector<int> nums; for (int i = 0; i < 5; i++) { int num; std::cin >> num; nums.push_back(num); }
coal
same in C, you ask for user input as many times as you need
coal
run the for loop for n amount of times until all the input you need was provided
\Device\NUL
i like c++
But the performance is different
coal
yeah it is different
coal
but at that level it probably doesnt matter
Lucas
I basically got a udemy course for free, I'm thinking of getting a c++ course focused on developing projects, do you have any recommendation?
coal
in my opinion, optimization should be done when there's an obvious bottleneck and making your code unreadable because it is nanoseconds faster is just nonsense
coal
I have a easy question , The user can enter as many numbers as they want, but there can be a maximum of 5 numbers, how can I limit this in the loop?
oh, you can also do while (std::cin >> num) and check within the loop if there's more than 5 numbers already
Melbgm
what is the issue
what I mean is that the user determines how many numbers it will enter beforehand, it can be 3, it can be 5, but it can't be 6, how can I do this?
coal
std::cin returns a truthy value if there's still input available
Melbgm
i cant understand the c++ the std is integer or someth ?
coal
what I mean is that the user determines how many numbers it will enter beforehand, it can be 3, it can be 5, but it can't be 6, how can I do this?
oh: int nums_length; std::cin >> nums_length; if (nums_length > 5) { std::cout << "You cant enter more than 5 numbers" << std::endl; return; } std::vector<int> nums; int num; for (int i = 0, i < nums_length; i++) { std::cin >> num; nums.push_back(num); }
coal
the - 1 is included because i assume the value is 1-based
coal
wait, mb
coal
actually wasnt necessary oops
Melbgm
can you write it in c ?
\Device\NUL
nvm
coal
yeah its time complexity is n
coal
because thats the limit of the loop
\Device\NUL
can you write it in c ?
If you understand array and basic loop it's should be easy
coal
can you write it in c ?
yes but if you can do it yourself and learn with it then that's better
Melbgm
Okay thanks
CALVIN
use a vector
Please drop here a simple example and how you stored the numbers even....
\Device\NUL
Please drop here a simple example and how you stored the numbers even....
Internet exist, use search engine to search vector example
coal
nums.push_back(num)
coal
std::cout << nums[0]
CALVIN
Thanks hey....
donald
can someone help me create a project about the sleeping of the fingerprint module in order to save electricity?
Suka
can someone help me create a project about the sleeping of the fingerprint module in order to save electricity?
its depend on your FP module, read the datasheet for suspend or sleep function
Harry
/get cbook
Harry
/get cppbookguide
Anonymous
Hello , Consider we have following structure typedef struct{ int *data; }my_struct; Now how accsess the value of address data point ? int a = 0; my_struct T1; T1.data = &a; T1.(*data) = 100;//Syntax error
Pranjal
// Create class "Car" ; Include 2 private data (use getter/ setter) // Include 2 public data. // Include necessary method to set and get the data
Pranjal
Can anybody provide some idea to solve this?
klimi
I would start in writing the code
Pranjal
I would start in writing the code
#include <iostream> using namespace std; class Car { public: string ownername; string car_color; int setcarno(string c){ car_no= c; } string getcarno(int){ return car_no; } char setbrand(string b){ brand= b; } string getbrand(char){ return brand; } private: int car_no; string brand; }; int main(){ Car car1; car1.ownername = "Dhiru" ; cout << "Name of car owner is " << car1.ownername<<endl; car1.car_color = "black"; cout <<"the colour of car is " << car1.car_color<<endl; car1.setcar_no("ba1kha2323") cout <<"the car no is " << car1.setcar_no(); car1.setbrand("pranjal") cout <<"the car no is " << car1.setbrand(); }
Pranjal
Thanks
MR
Please guys , Am having problem installing Mingw compiler on my PC( am using windows 8 version) I want to add path variable on advance setting but it is not allowing me to insert it
MR
As administrator ?
I installed visual studio code ide and I need a compiler
klimi
I installed visual studio code ide and I need a compiler
maybe you can specify it in vscode too... idk much about windows nor vscode
Max
Which of the 1-2 year students (18-20 years old) wants to try to improve their skills together and try even new things in C \ C ++ during these winter holidays? In the future, I will be glad to continue to cooperate Theme options: Lists (singly linked doubly linked ...) Trees Heap Stack Graphs Asymptotic analysis O big o small
klimi
?
klimi
if you don't provide more information, no on will be even able to help you if they wanted
klimi
\Device\NUL
Well, I compile it wil -Wall and -pedantic-errors and nothing wrong with the program No warn or Compile Error
Anonymous
*(T1.data) is this work ?
Yes , thank a lot
\Device\NUL
No
\Device\NUL
Yes
\Device\NUL
I think OS or Compiler doesn't matter as long as the code is following Standard
Nothing
Is there a program that checks the mysql code if it is correct or incorrect?
\Device\NUL
Try to recompile
Anonymous
hi