Phoenix
Oh is it necessary?
Phoenix
Will i have to use pointers or reference variables for doing this?
Phoenix
\Device\NUL
Prabhat
Where should I look it I want to study pointers in detail?
Cybersecurity Engineer
Hi I’m new here I want learn C programming language need your help suggestions and your guide🙏🏽
Çağlar
As for me, we should make a list or program for the new programmers. list may includes programming subject and excercises so when juniours are attend the page they can easily take the program it just only suggestion : )
Pavel
Deepak
Best playlist for learning python
For beginners.?
Dr
Anonymous
Now days which are the best course to learn easy or beginning of the programming language please suggest
M
Hey folks
Captain
Markiyan
Hi guys, my task is to create (let's say db) for toys using array of structures, where you can enter some data, display, filter by child age, sort it by name or by price. I have 2 issues:
1) This string always appears after executing command
user@user-Latitude-7480:~/labs$ ./a.out
List of commands:
(E)nter
Sort by (N)ame
Sort by (P)rice
(F)ilter by minimal age
(D)isplay all
(Q)uit
Choose command: D
Name Price Maker Child age
0.00 0
0.00 0
0.00 0
0.00 0
0.00 0
0.00 0
**Choose command: Such command doesn't exist**
Choose command:
Markiyan
2) I don't know how to create sort of whole array
Markiyan
Here is source code
Markiyan
#include <stdio.h>
struct toy
{
char name[10];
float price;
char maker[10];
int min_age;
} record[5];
void enter(int i)
{
printf("Enter name: ");
scanf("%s", record[i].name);
printf("Enter price: ");
scanf("%f", &(record[i].price));
printf("Enter maker: ");
scanf("%s", record[i].maker);
printf("Enter minimal age: ");
scanf("%d", &(record[i].min_age));
}
void display()
{
int i;
printf("\nName\tPrice\tMaker\tChild age\n");
for(i=0;i<=5;++i)
{
if(record[i].price = 0.0)
{
break;
}
printf("%s\t%.2f\t%s\t%d\n", record[i].name, record[i].price, record[i].maker, record[i].min_age);
}
}
void filter(){
int i, age;
printf("Enter child age: ");
scanf("%d", &age);
printf("\nName\tPrice\tMaker\tChild age\n");
for(i=0;i<=5;++i)
{
if (record[i].min_age == age)
{
printf("%s\t%.2f\t%s\t%d\n", record[i].name, record[i].price, record[i].maker, record[i].min_age);
}
}
}
void main()
{
int i = 0;
char command;
printf("List of commands:\n(E)nter\nSort by (N)ame\nSort by (P)rice\n(F)ilter by minimal age\n(D)isplay all\n(Q)uit\n");
while(1)
{
printf("\nChoose command: ");
scanf("%c", &command);
switch(command)
{
case 'E':
enter(i);
++i;
break;
case 'N':
printf("sort(name);");
break;
case 'P':
printf("sort(price);");
break;
case 'F':
filter();
break;
case 'D':
display();
break;
case 'Q':
return;
default:
printf("Such command doesn't exist\n");
break;
}
}
}
Markiyan
Thanks in advance
Anonymous
Assalamualaikum
Anonymous
I want to learn c language from starting any one teach me here plzzzz plzzzzzzzzzzz plzzzzzzzzzzz
Cybersecurity Engineer
/get
\Device\NUL
\Device\NUL
\Device\NUL
Markiyan
Choose command: Such command doesn't exist
\Device\NUL
M
No github links allowed? That is kind of weird though wouldn't you think
Markiyan
\Device\NUL
Markiyan
You mean like this?
```
struct toy
{
char name[10];
float price = 0.0;
char maker[10];
int min_age;
} record[5];
```
\Device\NUL
Anonymous
Hello guys can anyone help me please
Anonymous
I have a code, it's giving me a segmentation fault
But i cannot find the error
Anonymous
So can someone verify it for me
\Device\NUL
Just dontasktoask
Anonymous
What's that?
\Device\NUL
Anonymous
#include<stdio.h>
void printArray(int *A, int n)
{
for(int i = 0;i < n; i++)
{
printf("%d ", A[i]);
}
printf("\n");
}
void merge(int A[],int mid,int low,int high)
{
int i,j,k,B[100];
i=low;
j=mid+1;
k=low;
while(i<= mid && j <= high)
{
if(A[i]<A[j])
{
B[k]=A[i];
i++;
k++;
}
else
{
B[k]=A[j];
j++;
k++;
}
}
while(i<=mid)
{
B[k]=A[i];
k++;
i++;
}
while(j<=high)
{
B[k]=A[j];
k++;
i++;
}
for(i=low;i<=high;i++)
{
A[i]=B[i];
}
}
void mergeSort(int A[],int low,int high){
int mid;
if(low < high)
{
mid= (low + high)/2;
mergeSort(A,low,mid);
mergeSort(A, mid+1, high);
merge(A, mid, low, high);
}
}
int main()
{
int A[]={2,7,4,4,11,21};
int n=6;
printArray(A, n);
mergeSort(A, 0, 5);
printArray(A, n);
return 0;
}
\Device\NUL
#include<stdio.h>
void printArray(int *A, int n)
{
for(int i = 0;i < n; i++)
{
printf("%d ", A[i]);
}
printf("\n");
}
void merge(int A[],int mid,int low,int high)
{
int i,j,k,B[100];
i=low;
j=mid+1;
k=low;
while(i<= mid && j <= high)
{
if(A[i]<A[j])
{
B[k]=A[i];
i++;
k++;
}
else
{
B[k]=A[j];
j++;
k++;
}
}
while(i<=mid)
{
B[k]=A[i];
k++;
i++;
}
while(j<=high)
{
B[k]=A[j];
k++;
i++;
}
for(i=low;i<=high;i++)
{
A[i]=B[i];
}
}
void mergeSort(int A[],int low,int high){
int mid;
if(low < high)
{
mid= (low + high)/2;
mergeSort(A,low,mid);
mergeSort(A, mid+1, high);
merge(A, mid, low, high);
}
}
int main()
{
int A[]={2,7,4,4,11,21};
int n=6;
printArray(A, n);
mergeSort(A, 0, 5);
printArray(A, n);
return 0;
}
Is mergeSort func recursive ?
Anonymous
Yes
Anonymous
(Low < high)
Anonymous
this is not related about C/C++ but can i someone explain me or show me what and how to do the system integration design?
Melbgm
Hi guys. I am new to C programming. If the amount is 200 or more, how can I write the job of finding the discounted amount by making a 25% discount on the second product?
Melbgm
oid main() {
float price1;
float price2;
float totalprice;
float discount_amount;
float discounted_price;
printf("\n\n Enter Price of first Item : ");
scanf("%f", &price1);
printf("\n\n Enter Price of second Item : ");
scanf("%f", &price2);
totalprice = price1 + price2;
if (totalprice > 200)
discount_amount = (25 * price2) / 100;
discounted_price = (totalprice - discount_amount);
printf("\n\nDiscount amount : %f \n\n", discount_amount);
printf("Discounted price : %f \n\n", discounted_price);
// getch();
}
Melbgm
what is wrong with my code ?
\Device\NUL
Melbgm
normally it says void main, incompletely copied
\Device\NUL
\Device\NUL
Melbgm
oh 😱 You're right
Melbgm
#include <stdio.h>
void main() {
float price1;
float price2;
float totalprice;
float discount_amount;
float discounted_price;
printf("\n\n Enter Price of first Item : ");
scanf("%f", &price1);
printf("\n\n Enter Price of second Item : ");
scanf("%f", &price2);
totalprice = price1 + price2;
if (totalprice > 200) {
discount_amount = (25 * price2) / 100;
}
discounted_price = (totalprice - discount_amount);
printf("\n\nDiscount amount : %f \n\n", discount_amount);
printf("Discounted price : %f \n\n", discounted_price);
// getch();
}
Melbgm
still not working do you have any other solution
\Device\NUL
\Device\NUL
Also, how hard to use int main rather than void main
Melbgm
Melbgm
Changing it
Melbgm
Melbgm
#include <bits/stdc++.h>
int main() {
float price1;
float price2;
float totalprice;
float discount_amount;
float discounted_price;
}
printf("\n\n Enter Price of first Item : ");
scanf("%f", &price1);
printf("\n\n Enter Price of second Item : ");
scanf("%f", &price2);
totalprice = price1 + price2;
if (totalprice > 200) {
discount_amount = (25 * price2) / 100;
}
if else (totalprice <=200) {
discount_amount = (0 * price2) / 100;
}
discounted_price = (totalprice - discount_amount);
printf("\n\nDiscount amount : %f \n\n", discount_amount);
printf("Discounted price : %f \n\n", discounted_price);
// getch();
}
Melbgm
Any idea ?
shriman_deepak
shriman_deepak
https://pastebin.com/b1yvVWBy
Nana
Hello
Nana
I need your help guys
Nana
7. Name Arranger
Write a program that asks for the user’s first, middle, and last names. The names
should be stored in three different character arrays. The program should then store,
in a fourth array, the name arranged in the following manner: the last name followed
by a comma and a space, followed by the first name and a space, followed by the
middle name. For example, if the user entered “ Carol Lynn Smith”, it should store
“ Smith, Carol Lynn” in the fourth array. Display the contents of the fourth array
on the screen.
Nana
#include <iostream>
#include <cstring>
using namespace std;
void name_arrangement(char [], char[], char[]);
void intro();
int main()
{
int length = 50;
char first_name[length];
char last_name[length];
char middle_name[length];
intro()
cout<<"Enter your first name: ";
cin.getline(first_name, length);
cout<<endl;
cout<<"Enter your second name: ";
cin.getline(last_name, length);
cout<<endl;
cout<<"Enter your middle name: ";
cin.getline(middle_name, length);
cout<<endl;
name_arrangement(first_name, last_name, middle_name);
return 0;
}
void intro()
{
cout<<"This is a name arrangement program in C++\n";
cout<<"-------------------------------------------\n";
cout<<endl;
}
void name_arrangement(char first_name[], char last_name[], char middle_name[])
{
while(*first_name != '\0')
{
if(strcmp(first_name, last_name) < 0)
{
if(strcmp(last_name, middle_name) < 0)
cout<<last_name<<" "<<first_name<<" "<<middle_name<<endl;
}
else if(strcmp(first_name, last_name) > 0)
{
if(strcmp(last_name, middle_name) > 0)
cout<<last_name<<" "<<first_name<<" "<<middle_name<<endl;
}
first_name++;
}
}
Nana
#include <iostream>
#include <cstring>
using namespace std;
void name_arrangement(char [], char[], char[]);
void intro();
int main()
{
int length = 50;
char first_name[length];
char last_name[length];
char middle_name[length];
intro()
cout<<"Enter your first name: ";
cin.getline(first_name, length);
cout<<endl;
cout<<"Enter your second name: ";
cin.getline(last_name, length);
cout<<endl;
cout<<"Enter your middle name: ";
cin.getline(middle_name, length);
cout<<endl;
name_arrangement(first_name, last_name, middle_name);
return 0;
}
void intro()
{
cout<<"This is a name arrangement program in C++\n";
cout<<"-------------------------------------------\n";
cout<<endl;
}
void name_arrangement(char first_name[], char last_name[], char middle_name[])
{
while(*first_name != '\0')
{
if(strcmp(first_name, last_name) < 0)
{
if(strcmp(last_name, middle_name) < 0)
cout<<last_name<<" "<<first_name<<" "<<middle_name<<endl;
}
else if(strcmp(first_name, last_name) > 0)
{
if(strcmp(last_name, middle_name) > 0)
cout<<last_name<<" "<<first_name<<" "<<middle_name<<endl;
}
first_name++;
}
}
This is my code
Nana
The else if part does not work. I don't know how to store the sorted names in a fourth variable. Pls help me
klimi
?
Nana
No. sorting should be done using strcmp() in c++
Nana
Anonymous
how to see defination in vscode