I am trying to write C programming code and output will be as below
but I donno how to get the result analysis part.
help me to add the 2nd part with my code:
here is my code below:
#include <stdio.h>
#define MAX 100
struct studentMarkVariable{
int id;
float marks;
};
void getData(struct studentMarkVariable arrs[]);
void show(struct studentMarkVariable arrs[]);
int main()
{
printf ("####### Marks Analyzer V3.0 ####### \n");
struct studentMarkVariable
arrs[MAX];
getData(arrs);
show(arrs);
return 0;
}
void show( struct studentMarkVariable arrs[]){
int count=0;
do
{
if (arrs[count].id!= -1
&& arrs[count].marks != -1){
printf("%d. %d, %.2f\n",count+1,arrs[count].id ,
arrs[count].marks);}
else return;
count++;
}while(count<5);
}
void getData( struct studentMarkVariable arrs[]){
int count=0;
do
{
printf("Enter student id and marks (eg. 12345 89.5):");
int checker1;
float checker2;
scanf("%d",&checker1);
if (checker1 != -1){
(arrs[count].id)=checker1;
}
else{
arrs[count].id= -1;
return;
}
scanf("%f",&checker2);
if (checker2 != -1){
(arrs[count].marks)= checker2;
}
else { arrs[count].marks= -1;
return;}
count++;
}while(count<5);
}
Program:
#include <stdio.h>
#define MAX 100
//struct to define id and marks
struct studentMarkVariable
{
int id;
float marks;
};
//function prototypes
void getData(struct studentMarkVariable arrs[]);
void show(struct studentMarkVariable arrs[]);
int main()
{
printf ("####### Marks Analyzer V3.0 #######
\n");
struct studentMarkVariable arrs[MAX];
//call the method that read data from user
getData(arrs);
//method that shows analysis
show(arrs);
return 0;
}
//function that takes stict array as parameter and displays thae
analysis
void show( struct studentMarkVariable arrs[])
{
float sum=0, avg, lowestmarks=0,highestmarks=0;
int count=0;
do
{
//if the id and marks are not
-1
if (arrs[count].id!= -1 && arrs[count].marks
!= -1)
{
//print the id
and marks
printf("%d. %d,
%.2f\n",count+1,arrs[count].id , arrs[count].marks);
//get the sum of
marks of all the students
sum =
sum+arrs[count].marks;
//if the marks
are of 1st student set lowest and highes as marks of 1st
student
if(count==0)
{
highestmarks=arrs[count].marks;
lowestmarks=arrs[count].marks;
}
else
{
//compare highestmarks with each students marks
and get the highestmarks
if(arrs[count].marks>highestmarks)
highestmarks=arrs[count].marks;
//compare lowestmarks with each students marks
and get the lowestmarks
if(arrs[count].marks<lowestmarks)
lowestmarks=arrs[count].marks;
}
}
count++;
}while(count<5);
//calculate average
avg=sum/(count-1);
//dispaly results
printf ("\n### result of marks analysis ###
\n");
printf("average: %.2f, highest marks: %.2f, lowest
marks: %.2f",avg,highestmarks,lowestmarks);
}
//method that read students details into structure array
void getData( struct studentMarkVariable arrs[])
{
int count=0;
do
{
printf("Enter student id and marks
(eg. 12345 89.5):");
int checker1;
float checker2;
//read the id, add into array if it
is not -1
scanf("%d",&checker1);
if (checker1 != -1)
{
(arrs[count].id)=checker1;
}
//if -1 is entered exit loop
else
{
arrs[count].id= -1;
return;
}
//read the marks, add into array if
it is not -1
scanf("%f",&checker2);
if (checker2 != -1)
{
(arrs[count].marks)=
checker2;
}
//if -1 is entered exit loop
else
{
arrs[count].marks= -1;
return;
}
count++;
}while(count<5);
}
Outptut:
I am trying to write C programming code and output will be as below but I...
Programming in C: I am trying to modify this linked list to be doubly linked list. I’m also trying to add a print in reverse function. I’m really struggling with how to change the insert function to doubly link the nodes without effecting the alphabetical sorting mechanism. Example of desired output: Enter your choice: 1 to insert an element into the list. 2 to delete an element from the list. 3 to end. ? 1 Enter a character: a The...
I am trying to figure out why my C code is outputting "exited, segmentation fault". The game is supposed to generate 4 random numbers and store them in the "secret" array. Then the user is suppose to guess the secret code. The program also calculates the score of the user's guess. For now, I printed out the random secret code that has been generated, but when the game continues, it will output "exited, segmentation fault". Also, the GetSecretCode function has...
C programming - This is what I have so far but it is not working correctly. It must contain the function and it also needs a provision to write output to a file. Can anyone help? #include <stdio.h> I #include <math.h int main (void) int V float Rint, RLE0, 0; printf New power supply voltage scanf ("td", &V) printf Enter a valid Internal Resistance (Rint) range between 200 and 5k ohms: scanf ("tf", Rint if (V> 1 && VK 15)...
****Using C and only C**** I have some C code that has the function addRecord, to add a record to a linked list of records. However, when I run it, the program exits after asking the user to input the address. See picture below: Here is my code: #include<stdio.h> #include<stdlib.h> struct record { int accountno; char name[25]; char address[80]; struct record* next; }; void addRecord(struct record* newRecord) //Function For Adding Record at last in a SinglyLinkedList { struct record *current,*start,*temp;...
In C , checks if the entered password for admin is correct by calling checkAdminPassword. Part of this function has been implemented, complete the statement in if(). Keep in mind that the entered password is plaintext whereas the password in struct user is in the hashsed form. The password for user admin is “s#1Pa5”. int checkAdminPassword(char* password, struct user* users, int count) { for (int i = 0; i < count; ++i) { if (strcmp((users + i)->username, "admin") == 0)...
Hello, I am having trouble with a problem in my C language class. I am trying to make a program with the following requirements: 1. Use #define to define MAX_SIZE1 as 20, and MAX_SIZE2 as 10 2. Use typedef to define the following struct type: struct { char name[MAX_SIZE1]; int scores[MAX_SIZE2]; } 3. The program accepts from the command line an integer n (<= 30) as the number of students in the class. You may assume that the...
I am trying to add a string command to my code. what am i doing wrong? #define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <stdio.h> #include <string.h> #include <math.h> int main(void) { int i, j; int rowA, colA, rowB, colB; int A[10][10], B[10][10]; int sum[10][10]; char str1[10]; printf("This is a matrix calculator\n"); //read in size from user MATRIX A printf("Enter in matrix A....\n"); printf("\t#row = "); scanf("%d", &rowA); printf("\t#col = "); ...
I am trying to change my code so i no longer need the function that reads in the users base and height input but rather uses the implementation of argument vector in C. I want to accept command line arguments and have it calculate my area. so i want to type this into the command line and have it calculate my area project1 5 4 #include <stdio.h> void userDimensions(float *base, float *height) { scanf("%f", base); scanf("%f", height); } float calcArea(float...
C programming Rewrite the following code replacing the else-if construct with a switch statement. Make sure you test your code. Supplied code #include <stdio.h> int main(void) { char ch; int countA = 0; int countE = 0; int countI = 0; printf("Enter in a letter A, E, or I.\n"); scanf(" %c", &ch); //Replace the following block with your switch if(ch == 'E' || ch == 'e') countE++; else if(ch == 'A' || ch == 'a') countA++; else if(ch == 'I'...
C code program help. I am trying to find the total parallel resistive load. This is what I have so far. It does run, it does ask for numbers. But it doesn't calculate. It just comes out "The parallel is: 0.00". I have tried 3, 4, 5 and 3.2, 4.3, 5.4. Still only shows 0.00. I have tried several combinations of putting different data types in both main.c and the rest of it. Any help or ideas would be helpful....