Search the Community
Showing results for tags 'c programming'.
-
Good day everyone, I'm new in programming and using c language, I'am currently exploring and trying out but I expected my program to work but I don't know what the problem, What should I do? #include<stdio.h> void Entry_Array() { int Em_Num[10],a,r,c,t,p,s,m; int Hours_W[10]; char Em_Stat[10]={'r','R','p','P','c','C','t','T'}; char C_Stat[10]={'s','S','m','M'}; printf("Enter the Employee Number:\n"); for(a=0;a<10;a++) { scanf("%d",&Em_Num[a]); } printf("Enter the Employment Status:\n"); for(a=0;a<10;a++) { scanf("%s",&Em_Stat[a]); } printf("Enter the Civil Status:\n"); for(a=0;a<10;a++) { scanf("%s",&C_Stat[a]); } printf("Enter the Hours Work:\n"); for(a=0;a<10;a++) { scanf("%d",&Hours_W[a]); } for(a=0;a<10;a++) { printf("\nEmployee Number:%d\n",Em_Num[a]); printf("Employment Status:%c\n",Em_Stat[a]); printf("Civil Status:%c\n",C_Stat[a]); printf("Hours Work:%d\n",Hours_W[a]); } } void Search_Array() { int Em_Num[10],a,r,c,t,p,s,m; int Hours_W[10],Search,Flag; int G_Inc,Net_Inc,RPD,RPH,OTH,OT,Basic,P_Health; float SSS,P_i,T_Ded; char Em_Stat[10]={'r','R','p','P','c','C','t','T'}; char C_Stat[10]={'s','S','m','M'}; printf("Enter the Employee Number to be Search:"); for(a=0;a<10;a++) { scanf("%d",&Search); } printf("\n"); for(a=0;a<10;a++) { if(Em_Num[a]==Search) { Flag=1; break; } } if(Flag==1) { switch(Em_Stat[a]) { case 'R': RPD=800; break; case 'P': RPD=600; break; case 'C': RPD=500; break; case 'T': RPD=450; break; default: RPD=400; break; } RPH=RPD/8; if(Hours_W[a]>120) { OTH=Hours_W[a]-120; OT=1.5*(RPH*OTH); Basic=120*RPH; G_Inc=Basic+OT; } else { Basic=Hours_W[a]*RPH; G_Inc=Basic; } if(C_Stat[a]=='S'||C_Stat[a]=='s') { P_Health=500; } else if(C_Stat[a]=='M'||C_Stat[a]=='m') { P_Health=300; } else { P_Health=400; } if(G_Inc>12000) { SSS=0.1; P_i=0.05; } else if(G_Inc>5000) { SSS=0.08; P_i=0.03; } else if(G_Inc<=5000) { SSS=0.05; P_i=0.02; } T_Ded=P_Health+SSS+P_i; Net_Inc=G_Inc-T_Ded; printf("\nEmployee Number:%d\n",Em_Num[a]); printf("Employment Status:%c\n",Em_Stat[a]); printf("Civil Status:%c\n",C_Stat[a]); printf("Hours Work:%d\n",Hours_W[a]); printf("Gross Income=%d",G_Inc); printf("Total Deduction=%f\n",T_Ded); printf("Net Income=%d\n",Net_Inc); } else { printf("\nEmployee Number is not Found"); } } void Update_Array() { int Em_Num[10],a,r,c,t,p,s,m; int Hours_W[10],Search,Flag,TBU,TU; int G_Inc,Net_Inc,RPD,RPH,OTH,OT,Basic,P_Health; float SSS,P_i,T_Ded; char Em_Stat[10]={'r','R','p','P','c','C','t','T'}; char C_Stat[10]={'s','S','m','M'}; printf("Enter the Employee Number to be Updated:\n"); scanf("%d",&TBU); for(a=0;a<10;a++) { if(Em_Num[a]==TBU) { printf("Enter the Values to Update:\n"); scanf("%d",&TU); Em_Num[a]=TU; printf("Successfully Updated the Values\n"); } else { printf("The Employee Number does not exist\n"); } } } void Display_Array() { int Em_Num[10],a,r,c,t,p,s,m; int Hours_W[10],Search,Flag,TBU,TU; int G_Inc,Net_Inc,RPD,RPH,OTH,OT,Basic,P_Health; float SSS,P_i,T_Ded; char Em_Stat[10]={'r','R','p','P','c','C','t','T'}; char C_Stat[10]={'s','S','m','M'}; switch(Em_Stat[a]) { case 'R': RPD=800; break; case 'P': RPD=600; break; case 'C': RPD=500; break; case 'T': RPD=450; break; default: RPD=400; break; } RPH=RPD/8; if(Hours_W[a]>120) { OTH=Hours_W[a]-120; OT=1.5*(RPH*OTH); Basic=120*RPH; G_Inc=Basic+OT; } else { Basic=Hours_W[a]*RPH; G_Inc=Basic; } if(C_Stat[a]=='S') { P_Health=500; } else if(C_Stat[a]=='M') { P_Health=300; } else { P_Health=400; } if(G_Inc>12000) { SSS=0.1; P_i=0.05; } else if(G_Inc>5000) { SSS=0.08; P_i=0.03; } else if(G_Inc<=5000) { SSS=0.05; P_i=0.02; } T_Ded=P_Health+SSS+P_i; Net_Inc=G_Inc-T_Ded; printf("\nEmployee Number:%d\n",Em_Num[a]); printf("Employment Status:%c\n",Em_Stat[a]); printf("Civil Status:%c\n",C_Stat[a]); printf("Hours Work:%d\n",Hours_W[a]); printf("Gross Income=%d",G_Inc); printf("Total Deduction=%d\n",T_Ded); printf("Net Income=%d\n",Net_Inc); } void Choice() { int Choice; char Answer; do { printf("----MENU----\n\n 1.ENTRY \n 2.SEARCH \n 3.UPDATE \n 4.DISPLAY \n 5.EXIT\n\n"); printf("Enter Choice: "); scanf("%d",&Choice); switch(Choice) { case 1: Entry_Array(); break; case 2: Search_Array(); break; case 3: Update_Array(); break; case 4: Display_Array(); break; case 5: printf("Do you want to Exit?"); break; default: printf("Invalid Input\n"); break; } printf("Do you wish to exit[y/n]:\n"); scanf("%s",&Answer); }while(Answer=='n'||Answer=='N'); } void main() { Choice(); }
-
Hi all, Firstly, I've tried the Arduino forums for help however their account system seems to be a bit broken... (I'm logged in for the account page, I then go to the forum and I'm not logged in, I then log in to find my password is apparently incorrect...) Anyway that's besides the point. Does anyone know how to get the MAC address of a device connected to a HC-05 bluetooth module on an arduino in C? This is so I can get the MAC address of the device and authenticate it in the arduino it's self. Thanks in advance!
-
From my understanding a pointer is a variable whose value is a memory address of another variable. And that you declare a pointer like so: int *test; So i know what a pointer is and that it's used for passing by reference, but what confuses me is following where a pointer points to in a program. For example this program: #include<stdio.h> void up_case(char *c) { if (*c>='a' && *c<='z') *c-=32; } void lo_case(char *c) { if (*c>='A' && *c<='Z') *c+=32; } void traverse(char *s, void (*f) (char *)) { while (*s!='\0') { f(s); s++; } } int main() { char str[]="CTEC2901 Data Structure and Algorithms"; printf("Original: \'%s\'\n",str); traverse(str,up_case); printf("Upper Case: \'%s\'\n",str); traverse(str,lo_case); printf("Lower Case: \'%s\'\n",str); return 0; } I do understand this program, but what i don't get is what char *c in the up_case and lo_case function point to, as well as the char *s, void (*f) and char * in the traverse function. My guess is that char *c in the up_case and lo_case point to the value thats given in. The same with the traverse function char *s points to the char array called str, and the *f points is clearly a function pointer so it would point to either lo-case or up_case. Like I said i'm not really sure, so if someone could talk me through where each pointer points to in each function I'd be greatful.
- 7 replies
-
- pointers
- pass by reference
-
(and 3 more)
Tagged with:
-
hi all ! iam an Avionics and robotics engineering student and iam learning C language. now my question is how can i learn all C language family ( C, C++, C#) simultaneously and be effective at them ? can you guys inspire me with how powerful they are? as i was told that C language usability is like a Swiss Knife! Lol any opinions will be more than appreciated. thanks alot.
- 5 replies
-
- programming
- embedded systems
- (and 4 more)
-
i want to make a calculator in java.i want to take user inputs from jbuttons and make it display in the textfield and i want to store each digit on a array
- 3 replies
-
- netbeans
- programming
-
(and 3 more)
Tagged with:
-
I have this program which follows this: Write a C program checkout.c that adds up numbers as they are typed in. This is rather like scanning prices at a supermarket checkout. The program should repeatedly input float values representing prices (in pounds and pence such as 3.25) and keep a running total When the user enters a zero price the program should stop reading numbers and print out (a) the grand total and (b) the number of items. For example: Price? 0.54 Price? 2.23 Price? 0.77 Price? 1.99 Price? 0.00 ------ Total: 5.53 (4 items) However I've stuck with the part that asks me to count the number of items the user typed into the program. So far I've only thought of adding an int varaible called count. Now i'm not really sure where to place this count varaible. I tried adding another for loop but it didn't go so well. Here is my code so far: #include <stdio.h>int main(){ float price = 0, total = 0; int count = 0; do { printf(" Price: ", price); scanf(" %f", &price); total += price; } while (price > 0); printf( " Total: %.2f\n", total); printf( " %i items\n ", count); printf("\n"); return 0;} I'm sure it's something simple but I'm stumped. Any help is greatly appricated.
-
Basiclly I have a task to do which is: Write a C program charseq1.c that prompts the user to enter a two values; prints out the sequence of characters between the two values (inclusive). So, for example, if the user entered the characters D then N then the output would be: D E F G H I J K L M N Note, if the user had entered the characters in the opposite order (N then D) the ouptut would be blank. This implies that the program is counting upwards from the first character. It's challenging me a lot, we've just learnt about loops; while, for and do while but this task has me stumped. The only ideas I've had so far was to use the ASCII table where the dec value 97 is A and 122 is value Z. (In my code below) #include <stdio.h>int main(){ char letter; letter = 97; printf(" Enter your first letter "); scanf_s(" %c", &letter); printf(" Enter your second letter "); scanf_s(" %c", &letter); while (letter >= 97 && letter <= 122) return 0;} If anyone could help me finish this I'd be greatful. I've already tried understanding this but it doesn't really make sense. I think it's a different language.
- 2 replies
-
- c programming
- printing the alphabet between
- (and 2 more)
-
I've just been reading about loops in C programing, and I'm trying to work out the output of some example programs, however I really can't figure out this one (Image below) I understand up to the first Two output. But after that I can't see how Two is ouputted again. It's been confusing me for days. Could anyone explain this one, then maybe I can understand the rest of the examples simular to this. Any help would be appreciated.
- 3 replies
-
- c programming
- nested loops
- (and 6 more)
-
I have this code which uses the caesar cipher encryption method based on a users input, so the user enters the text then they enter the amount of times they want to shift the text. However I was wondering how I could make it so only the lower case letters would be shifted as specified. I was thinking of adding something like this: if (input[i] >= 97 && input[i] <= 122) But i'm not sure where to add it in my program which is this: #include<stdio.h> #include<string.h> int main() { int rotate, i; char input[80]; printf(" Enter the text you wish to be encrypted: \n"); gets(input); printf(" Enter the amount of times you want to rotate: \n"); scanf("%d",&rotate); if (rotate > 26) rotate = rotate % 26; //0 <= rotate < 26. for(i = 0; i < strlen(input); i++) { if(input[i] == ' ') { continue; } else { if(input[i] >= 'x') { input[i] = input[i] -26; } input[i] = input[i] + rotate; } } printf("Your encrypted text is: %s\n", input); } Could anyone advise me on this? I need only lower case letters to be caeser ciphered.
- 10 replies
-
- c programming
- caesar cipher
- (and 4 more)
-
Right so I made this little C program that lets a user input a string and then outputs that input to the console. I was wondering how I could reverse the string so that whatever the user enters is printed out backwards. Would a for or while loop or something suffice? I'm not really sure how i'd do this to be honest. I'm quite new to C programming and just need something simple for now. Here is the code for the program that just outputs the users input to the console. #include <stdio.h>int main(){ char str[80]; printf("Enter a string less than 80 characters: \n"); scanf("%[^\n]", str); printf("Your string is: \"%s\"\n", str); return 0;}
- 7 replies
-
- string
- c programming
-
(and 3 more)
Tagged with:
-
Right so I have this program that nearly works, the only thing that isn't working is printing out stars. What the program is supposed to do is match the amount of stars printed with each value in the array. Currently I have this code: #include <stdio.h>int main(){ char star = '*'; int i; //int s; int lottery[49] = { 23,16,18,19,26,13,22, /* 1 .. 7 */ 20,14,22,18,21,15,17, /* 8 .. 14 */ 24,15,18,20,13,14,20, /* 15 .. 21 */ 18,22,20,16,19,11,20, /* 22 .. 28 */ 16,28,22,20,15,17,17, /* 29 .. 35 */ 21,21,19,20,14,22,25, /* 36 .. 42 */ 19,17,26,18,20,23,12 }; /* 43 .. 49 */ for (i = 0; i < 49; i++) { printf(" %2d (%d) | %c\n", i+1, lottery[i], star); } return 0;} The program is supposed to do this in the (picture 1 below) But the output is currently this (picture 2 below)
- 11 replies
-
- c programming
- representing array values
- (and 3 more)
-
Right so I have to write this program which has these requirments: Write a program, perfect.c, that takes one integer parameter p checks whether p is perfect by adding up all the (positive) numbers less than p which divide it exactly returns 1 if p is perfect and 0 otherwise Create perfect.c by adding a main() function that computes all the perfect numbers less than 64,000. Compile and test your program. So basiclly I have to write a function to find the perfect number. Which is: In number theory, a perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself. So I've written the function and I've tested it and I know it works. However the code i've wrote in the main function doesn't seem to be calling the perfect function. If I type a number less than 64000 it always say it's a perfect number, which is exactly what I want the main function to do, however it doesn't seem to be using the perfect function to determine weather that said number is perfect or not. Only the main function seems to be being executed and i'm not sure why. Any help would be appreciated. Here is the code: #include <stdio.h> int perfect (int p) { int i, sum = 0; if (p%2==0) { for (i=1; i < p; i++) { sum = sum+i; if (sum == p) return 1; } } else return 0; } int main() { int n; printf("Enter a value: "); scanf("%i", &n); if (n < 64000) printf("%i is a perfect number", n, perfect(n)); else printf("Value is more than 64000", perfect(n)); return 0; }
- 1 reply
-
- c programming
- function
-
(and 1 more)
Tagged with:
-
Right so I'm back again with yet another programming question. This time I'm trying to create a program that converts an input string from the user into morse code. The only thing I can really think of so far is to create two arrays to store both the users string and the morse code symbols. Apart from that I have no idea really. I struggle with iterations. I know how they work when I see them but i find it almost impossible too implement my own. Any help would be greatly appreciated. And yes I know the gets function is a bad habit but i'm just trying to understand how to implment my own interations for now. Here is the code i've thought of so far: (I'm not even sure if my for loop is useful for this) EDIT: for some reason I can't set this code with C syntax highlighting. #include <stdio.h> #include <string.h> int main() { int i; char input[255], morse['o ---', '--- o o o', '--- o --- o', '--- o o', 'o', 'o o --- o', '--- --- o', 'o o o o', 'o o', 'o --- --- ---', '--- o ---', 'o --- o o', '--- ---', '--- o', '--- --- ---', 'o --- --- o', '--- --- o ---', 'o --- o', 'o o o', '---', 'o o ---', 'o o o ---', 'o --- ---', '--- o o ---', '--- o --- ---', '--- --- o o'] printf("Enter your string: "); gets(string); for (i = 0; input[i] != '\0'; i++) { if () } printf(" Your string in morse is: "); return 0; }
- 13 replies
-
- string to morse code
- c programming
-
(and 4 more)
Tagged with:
-
Hello guys, I'm in need of your assistance I need to make a C program with these conditions: Create a C program that will input a character, an integer and two float numbers. Output the character, the integer number and the float number. Output the integer on the screen with a minimum of 5 characters. Output the first float number with 5 characters with a maximum of 3 decimal places. Output the second float number with 2 characters with a maximum of 6 decimal places. Many thanks, friend of friends! Hi guys thanks for all the references. I got the hang of it in such a short time.
- 8 replies
-
- dev c
- c programming
-
(and 1 more)
Tagged with:
-
Hello guys and fellow programmers. I have a implementation of ORs and xORs that is still missing a very important key, their parameters p,q,&r and incrementing the parameters properly. Such that p q & r hold these values through each iteration of the for loop p q r 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 I was given the pseudocode for the permutations but can't figure out it's implementation into the forloop any ideas or help would be much appreciate. count++; p = count & 1; q = count & 2; r = count & 4; Time for the code! First the functions OR(implication) & xOR(biconditional) bool implication(bool a, bool b){ if (a || b)//if a or b is true { return true; } else {return false;}}//XOR Function//It's bi condition given that if a is true then b can't be true, if b is true than a can't be true//It's either one or the other NOT BOTHbool biconditional(bool a, bool b){ if (a != b) { return true; } else{ return false; } //Can only have 1 not 2} I won't post the entire source but there's a sample loop of what I'm doing to print out the truth tables I just can't figure out how to implement the permutations for p q and r /* TEST Bp q r | p and (q -> r) | (p and q) xor r0 0 0 | 0 | 00 0 1 | 0 | 10 1 0 | 0 | 00 1 1 | 0 | 11 0 0 | 1 | 01 0 1 | 1 | 11 1 0 | 0 | 11 1 1 | 1 | 0These expressions are NOT equivalent*/ printf("P | Q | R |p and (q->r)|(p and q)<->r\n"); for (int i = 1; i <= 8; ++i) { printf("%d | %d | %d | %d | %d\n", p, q, r, p&&(implication(q,r), biconditional(p&&q,r))); } printf("These expressions are NOT equivalent\n"); printf("\n\n"); Any ideas or hints as to how I can go about this? Please and thank you as always!
- 5 replies
-
- permutations
- xor
-
(and 3 more)
Tagged with:
-
I my program Visual studio says there is a syntax error a missing ( before indentifier I cant figger out why I am getting this error #include <stdio.h> #include <stdlib.h> void Pause(); void DisplayTotal(int BatchCostTotal); int GetBatchCostTotal (); void main() { float BatchCostTotal = 0; int BatchSize = 0; float CostOfRawMaterials = 0; float LabourHours = 0; float LabourHourlyRate = 0; float TotalLabourCosts = 0; float Product = 0; float ProfitMargin = 0; // Exites when two digets are entered for Batch Size // // And Cost of the Raw Meterials>? // printf(" Please enter the Batch Size "); scanf("%f" ,&BatchSize); printf(" Please enter the cost of the Raw Materials"); scanf("%f", &CostOfRawMaterials); printf(" Please enter the Number of Labour hours"); scanf("%f" ,&LabourHours); printf("Please enter the Hourly Rate"); scanf("%f", &LabourHourlyRate); printf(" Please enter the Target Profit Margin"); scanf("%f" ,&ProfitMargin); TotalLabourCosts= LabourHours * LabourHourlyRate; scanf("%f", &TotalLabourCosts Product= TotalLabourCosts + RawMaterials; scanf("%f" , &Product); //Calculations //Output // BatchCostTotal= GetBatchCostTotal (); // GetBatchCostTotal(BatchCostTotal); Pause(); } void Pause() { printf("\n\nPress the ENTER key to continue."); getchar(); }
-
i want to get a value from a column in my sql server database and display it in a label. so far i tried this but it didnt work.any suggestions how to get this working? SqlDataReader myReader = null; SqlCommand myCommand = new SqlCommand("select details from Pictures where id ='"+x+"'"); myReader = myCommand.ExecuteReader(); label1.Text = myCommand.ToString();
- 3 replies
-
- programming
- java
-
(and 3 more)
Tagged with:
-
I need help, I'm still a newbie and a beginner in the programming world.