.
get a year on the input and create multiple if else statements for different ranges you have there then choose a random year from the range
#include <stdio.h> #include <stdlib.h> #include <time.h> int main () { int inp; int ras1,ras2,ras3; srand(time(NULL)); ras1 = 2025 + rand() % 10; ras2 = 2040 + rand() % 15; ras3 = 2055 + rand() % 15; printf("Welcome to the great fortune teller!\n"); printf("Please input your birth year to learn the year that you will be a rich person: \n"); scanf("%d", &inp); if (inp<1980) { printf("Sorry if you are not yet, you will never be a rich person\n"); } else if (inp>= 1980 && inp<=1999) { printf("After %d years, at %d you will be a rich person",(ras1-2021), ras1); } else if (inp>=2000 && inp<=2014) { printf("After %d years, at %d you will be a rich person",(ras2-2021), ras2); } else if (inp>=2015 && inp<= 2021) { printf("After %d years, at %d you will be a rich person",(ras3-2021), ras3); } else { printf("There is a problem with your birth year"); } return 0; } Did it bro thanks si much🤝
Loner〽💻
int main() { int elem; int i; int x; int y; printf("How many elements you want to store ?:"); scanf("%d", &elem); int store [elem]; // what is the problem here? for (i = 0; i < elem; i++)
the value of elem has to be known at compile time and should not change later. That's how arrays roll in c/c++. for dynamic array try <vector>
HaiNahi
I made a program to make equations for any 1D pulley systems and solve the equations using cramers rule. Thinking how far this project can go.
A
hey , how find c++ full stack developer
\Device\NUL
does it work in c ? i thought it only works in c++
ISO C++ doesnt support VLA, it's GNU Extension. C99 and above support VLA. btw, vla is slow. Just allocate as much as you need
Kaashᅠ
tell me one thing, % and / .. Which one of two execute first?
I use Arch
tell me one thing, % and / .. Which one of two execute first?
/ and % have the same priority and left-to-right associativity. So the leftmost statement will be executed first
klimi
oh... this is very nice way how to send image when images are disable 👍 Why it is merged together? because you haven't flushed stdout
klimi
probably...
Suka
try use space before % like "<this is space>%d"
Nothing
Hello guys please can you help me I'm software student currently I'm learning C programming But when I'm trying to write code i can't do without looking from the internet What can i do to improve myself Kindly can you answer me
Ethan
A good programmer knows how to problems, we always look up code from the internet Dont feel bad if you look up syntax
coal
how do you expect to do something without knowing how
Nothing
Okey thank you all i appreciate your help
Nardi
Any one who knows how to solve quadratic equation in C program
Eda
Does anyone know about priority queue in c?
Unknown
I need someone help me code a sudoku puzzle in C but in easy way without user the pointer or something like that because it’s so hard to me as a beginner
Anonymous
Mainly backtracking
Unknown
Use recursion
Ok I will try it 👍 thank you
Anonymous
Can anyone please help me how to extract sub matrix from a matrix with the give sub matrix sum value?
mayway
I'm not getting CP.. please help me
Pavel
I'm not getting CP.. please help me
You can try to ask more specific questions then people will be able to answer them
Harun
Hello everyone Is there a C Legend who knows the use of comets from the C programming language data structures???
𝔓𝔢𝔫𝔡𝔯𝔞𝔤𝔬𝔫
Hi, guys. I have a question about multithreading. Assuming that in this function: https://pastebin.com/nqPbhrMa threads enters one by one and it has two mutexes (m, m1) can you tell if this part of program runs faster with multiple threads?
\Device\NUL
If you input with enter, there is remaining newline
Anonymous
Write a program to find out the sub-matrix of size 2x2 within a bigger matrix of size MxN (M >= 2, N >= 2), whose number sum to a specific given number
Anonymous
In C please, any idea really appreciated
Anonymous
Like If the absolute sum is 28 and the matrix is: 1 2 3 4 5 6 7 8 9 The sub-matrix will be: 5,6 8,9
Shailesh
I guess the problem is due to buffer cache. We usually do fflush before scanf
Shailesh
Put fflush(stdin);
Hima
Just add a single space between between " % in your second scanf
Hima
Send link to the code
Rio
How WE Can Do a Matrix using codeblocks c language
Rio
The matrix of real numbers A[m, n] is given. Determine the presence of any of the numbers in the range [0,5] and its locations (coordinates) separately in each matrix line by the method of binary search (Algorithm №2), if the elements of each row are ordered separately in non-incresing order.
Rio
If someone knows tell me 🙏🏻
•‿•
i have a question do i make a FILE in switch case statement ?
•‿•
???
i have a code can you check it ?
•‿•
???
#include <stdio.h> #include <stdlib.h> struct Medical_store { char name[100]; char composition[100]; int stock; int price; char location[100]; int retail; int profit; }; int main() { int choose; int i; int n_add; printf("Enter :"); scanf("%d", &choose); switch (choose) { case 1: { struct Medical_store *medicine; FILE *medi_add; medi_add = fopen("medicine.txt", "a"); printf("How many medicine do you want to add :\n"); scanf("%d", &n_add); medicine = (struct Medical_store *)malloc(n_add * sizeof(struct Medical_store)); printf("Size of n is %lu\n", *medicine); if (medicine == NULL || medi_add == NULL) { printf("Memory allocation failed \n"); exit(0); } else { for (i = 0; i < n_add; i++) { fprintf(medi_add, "%s %s %d %d %d %s", medicine[i].name, medicine[i].composition, &medicine[i].stock, &medicine[i].retail, &medicine[i].price, medicine[i].location); } } fclose(medi_add); } break; default: printf("Defult"); exit(0); } return 0; }
•‿•
look at this once
•‿•
Yeah you can make file in case or switch... it doesn't matter.
but it not working it just end after taking input of n_add
\Device\NUL
You need to clear input stream before next input
\Device\NUL
For example void clear(void) { char ch; while(ch = getchar() != '\n' && ch != EOF); } in C++, there's std::cin.ignore()
\Device\NUL
Put fflush(stdin);
That's not portable, Standard C/C++ doesn't define fflush(stdin) behaviour
Levi
can somebody what is suspicious pointer error please;
\Device\NUL
Just see any warn or error from the compiler
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
Hi guys, I have a problem I find hard to solve, because I don't understand were the problem is, so it makes it hard for me to search for a solution on google. Btw, if the question is not appropriate, I will delete it right away. I created a struct in this way: typedef struct node { int size; int left; int available= size - left; } typeNode; So, every time I try to access the attribute available like typeNode myNode; int value= myNode->available; Or any other possible way, I'm told that the struct typeNode (aka struct node) doesn't have a "available" attribute. Now, I don't know how to solve this. And I tried some researches on Google, but I don't know what the problem is here, so I can not search properly: pointers problem? Maybe the problem is that I can't have an attribute Which is a linear combination or a function of other attributes from the same struct? Does anyone happen to know my mistake (note: I'm new in C, just 2 months of C programming, so Perhaps, and very much likely will be, a stupid mistake, yet I can't really figure it out). Thank you!
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
Uhmmm, isn't myNode a variable struct, not a pointer ?
Ehm yes, but if you are referring to the fact that myNode-> attribute shouldn't work, it does with size and left
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
Well this is a node in a wider list, so when creating the list the parameters size and left are set, therefore available is set as their sub
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
Any idea how to fix it?
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
I'm really new on data structures
\Device\NUL
Any idea how to fix it?
-> is only work for pointer structs , use . to access normal structs members
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
Oh i didn't know that, so it's like python
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
It works, thank you!!
\Device\NUL
It works, thank you!!
But remember int available = size - left is undefined behaviour since size and left member is undefined
\Device\NUL
Please don't pm, ask in this group instead X
𝕷𝖔𝖗𝖊𝖓𝖟𝖔
But remember int available = size - left is undefined behaviour since size and left member is undefined
Well I'll think about that later, you fixed my problem and I thank you for that!
Prince Fine
Hey Guys can i link a Dictionary with my c++ code 👀 What I meant was like to check the word input was a correct word or not
Falcon
hi Guys
Falcon
how to send wchar_t data from wininet for upload file to web server ?
Prince Fine
AmR
I need some help with CMake And boost, Any one Can help me ?
AmR
I try build boost form .7z file But I can't make funded by cmake find pkg I try both FetchContent ExternalProject , My code https://pastebin.com/3iaT48N8