I am working on an assignment in C where I have to read in multiple people's heights and weights and determine their bmi. I then classify them into their respective bmi categories, but I am getting stuck on how to do this properly, this is my code thus far:
# include <stdio.h>
int main () {
int people;
double bmi, weight, inches;
printf("How many peoples? > ");
scanf("%d", &people);
do {
printf("Enter height (inches) and weight (lbs) (%d left) > ", people);
scanf("%lf %lf", &inches, &weight);
people--;
}
while (people > 0);
bmi = (weight / (inches * inches)) * 703;
if (bmi < 18.5) {
printf("Under weight: %d\n", people);
}
else if (bmi >= 18.5 && bmi < 25) {
printf("Normal weight: %d\n", people);
}
else if (bmi >= 25 && bmi < 30) {
printf("Over weight: %d\n", people);
}
else if (bmi >= 30) {
printf("Obese: %d\n", people);
}
return 0;
}
where am i going wrong? where do i fix this code?
Use some data structure for storing data. You are getting input for more than one people but, finally processed for one person.
And also people--; is done. so people variable is decremented up to zero, which makes while to exit without executing your BMI calculation.
Modified Code:
#include <stdio.h>
#define MAX_PEOPLE 100
int main () {
int people;
double bmi[MAX_PEOPLE], weight[MAX_PEOPLE], inches[MAX_PEOPLE];
int index = 0;
printf("How many peoples? > ");
scanf("%d", &people);
index = people;
do {
printf("Enter height (inches) and weight (lbs) (%d left) > ", index);
scanf("%lf %lf", &inches[index], &weight[index]);
index--;
}while (index > 0);
for(index = 0; index < people; index++)
{
bmi[index] = (weight[index] / (inches[index] * inches[index])) * 703;
if (bmi[index] < 18.5) {
printf("Under weight: %d\n", index);
}
else if (bmi[index] >= 18.5 && bmi[index] < 25) {
printf("Normal weight: %d\n", index);
}
else if (bmi[index] >= 25 && bmi[index] < 30) {
printf("Over weight: %d\n", index);
}
else if (bmi[index] >= 30) {
printf("Obese: %d\n", index);
}
}
return 0;
}
Right now you are processing the same data.
Each time you assign a new value to weight the old one is erased.
You could create multiple variables like so:
double weight1, weight2, weight3, weight4, ...etc (highly unpractical!!)
or
create an array of doubles:
double weight[100];
and refer to each specific double variable like this:
scanf("%lf %lf", inches[0], weight[0]);
scanf("%lf %lf", inches[1], weight[1]);
scanf("%lf %lf", inches[2], weight[2]);
You see where i-m getting at ? you can manipulate the array tru a for loop.
Related
I need some advice or hints about how to calculate the average of insurance, tax, gross and net salary. Just need some enlightment.
Tried to add average function before but it seems that its hard to get the value from other function.
Any ideas? This code is used to find the salary of employee and its average.
char EmpName[50];
int EmpID, EmpAge, EmpNum, i;
float gross_salary, net_salary;
float insurance, tax, total, total_insurance, total_tax;
int main()
{
int i;
FILE *file;
file = fopen("UserDetails.txt", "wt");
printf("Number of Employee to process: ");
scanf("%d", &EmpNum);
i = 1;
EmployeeName: while( i <= EmpNum)
{
printf("\nEmployee name: "); scanf("%s", &EmpName);
if (strlen(EmpName) <= 50){
EmployeeID: printf("Employee ID: "); scanf("%d", &EmpID);
if (EmpID >= 1000 && EmpID <= 9999){
EmployeeAge: printf("Employee Age: "); scanf("%d", &EmpAge);
if (EmpAge >= 18 && EmpAge <= 99){
printf("Employee Salary: "); scanf("%g", &gross_salary);
if (gross_salary >= 0.0 && gross_salary <= 9999.99){
goto Total;
}
}
else{
printf("\nInvalid Input!\nEmployee Age Is Between 18 To 99\n");
goto EmployeeAge;
}
}
else{
printf("\nInvalid Input!\nEmployee ID Number is Between 1000 To 9999\n");
goto EmployeeID;
}
}
else{
printf("\nInvalid Input!\nMax Character is 50\n");
goto EmployeeName;
}
Total: printf("\n");
SetInsurance(EmpAge);
IncomeTax(gross_salary);
TaxDeduction(tax);
InsuranceDeduction(insurance);
NetSalary();
Average(insurance,gross_salary,net_salary);
i++;
fprintf(file, "Employee name: %s\n", EmpName); //print data inside file
fprintf(file, "Employee ID: %d\n", EmpID);
fprintf(file, "Employee Age: %d\n", EmpAge);
fprintf(file, "Employee Salary: %g\n\n", gross_salary);
}
fclose(file);
}
float SetInsurance(int x){
while (i <= EmpNum){
if (x <= 35)
insurance = 110;
else if (x >=36 && x <= 65)
insurance = 160;
else if (x > 65)
insurance = 250;
else
printf("Under Age!");
total = insurance;
printf("\nInsurance: %.2f\n", total);
return total;i++;
};
}
float IncomeTax(float salary) {
int i = 0;
while(i < EmpNum){
if (salary <= 999.99)
tax = 0;
else if (salary >= 1000 && salary <= 2999.99)
tax = 2.5;
else if (salary >= 3000)
tax = 5;
else
printf("Invalid Input!\n");
printf("Income Tax Rate: %.2f%\n", tax);
return tax;
i++;
}
}
float InsuranceDeduction(float insurance){
if (insurance == 110){
total_insurance =+ 110;
}else if (insurance == 160){
total_insurance =+ 160;
}else if (insurance == 250){
total_insurance =+ 250;
}
return total_insurance;
}
float TaxDeduction(float tax){
if(tax == 2.5){
total_tax = gross_salary * 0.025;
}else if(tax == 5){
total_tax = gross_salary * 0.05;
}
return total_tax;
}
void NetSalary(){
total = TaxDeduction(tax) + InsuranceDeduction(insurance);
net_salary = gross_salary - total;
printf("Net Salary: RM%.2f\n", net_salary);
}
I order to solve the problem you face, I'd follow the recomendations you have received from other responses, and in addition:
If you fopen() a file, just check that the returned pointer is valid, as you can have several errors derived of:
Not having permissions to read the file.
file doesn't exist.
and these should be handled before you start processing the file.
Second, You don't need to store the data from the file, except for error purposes (it's preferable if you say that Martina Navratilova cannot be paying such ridiculous amount of taxes than saying that record 6437 in the file has a ridiculous amount of taxes to be payd -- you should search for it by counting, while your program has already done it)
If I would to decide how the input file is formatted, I should make a two line record, one line to specify the user name (which so, can have spaces embedded, as the new line marks the end of the name) so it can be read with fgets(), and a second line with all the numeric data you are going to fscanf(), after the sequence is done, you have all the data for a single user. Another possibility (to allow the name with spaces) is to put the name as the last field of the data file, so you can read all the last field characters upto the \n as the user name. This would allow to put each user in one single line
"I need some advice or hints., ...,any idea?"
First: Read and act on each of suggestions in first 3 comments under your post from #Chux.
Other suggestions:
Avoid using goto tag ... :tag statements to traverse code.
Create functions that can be called to do a simple task, then return.
Use a struct to contain related data when there can be more that one related data set.
Change
char EmpName[50];
int EmpID, EmpAge, EmpNum, i;
float gross_salary, net_salary;
float insurance, tax, total, total_insurance, total_tax;
To for example: (Note, not all these members may be necessary, depending on how you finally implement the records needed for each employee.)
typedef struct {
char EmpName[50];
int EmpID;
int EmpAge;
double gross_salary;
double net_salary;
double insurance;
double total_insurance; //may not be necessary in struct
double tax;
double total_tax; //may not be necessary in struct
}account_s;
Note, if "total" members are to be used as totals for all employees, then they should probably not be a members in the struct.
Create instance(s) of this struct in local space, Eg.
int main(void)
{
int EmpNum = 0;
...
printf("Enter number of Employees to process: ");
scanf("%d", &EmpNum);
account_s account[EmpNum];//creates an array of instances of account_s
memset(account, 0, sizeof account);//initializes array
Incorporate account_s into functions as return type, and/or function parameters. Eg.
The following is a very brief, but compilable and runable example to illustrate several things including how to pass a single function argument containing all the information needed to update and contain employee information (via struct).
//prototypes
void populateAccounts(int count, account_s record[count]);
void SetInsurance(account_s *record);
double Get_ave_salery(int c, account_s *account);
int main(void)
{
int EmpNum = 0;
printf("Number of Employee to process: ");
scanf("%d", &EmpNum);
account_s account[EmpNum];//creates an array of instances of account_s
memset(account, 0, sizeof account);//initializes array
populateAccounts(EmpNum, account);
double ave_salary = Get_ave_salery(EmpNum, account);
printf("Average Gross Salary: %lf\n", ave_salary);
return 0;
}
void populateAccounts(int count, account_s record[count])
{
//Read in information for each account
for(int i=0; i<count; i++)
{
printf("\nEnter employee name: ");
scanf("%s", record[i].EmpName);
printf("\nEnter employee ID: ");
scanf("%d", &record[i].EmpID);
printf("\nEnter employee Age: ");
scanf("%d", &record[i].EmpAge);
printf("\nEnter employee Salary: ");
scanf("%lf", &record[i].gross_salary);
SetInsurance(&record[i]);//function to set insurance via function argument
// etc.
}
}
void SetInsurance(account_s * record){
if (record->EmpAge <= 35)
record->insurance = 110;
else if (record->EmpAge >=36 && record->EmpAge <= 65)
record->insurance = 160;
else if (record->EmpAge > 65)
record->insurance = 250;
else
printf("Under Age!");
// total = record->insurance;
printf("\nInsurance: %.2f\n", record->insurance);
}
double Get_ave_salery(int c, account_s *account)
{
double ave = 0.0;
double sum = 0.0;
for(int i=0; i<c; i++)
{
sum += account[i].gross_salary;
}
return sum/c;
}
There is more for you to do here, but this should help you to get started.
I wanted to wrote a simple text game in C. The game generates random 2D position using 2 double variables in range from -10.000 to 10.000 (X, Y) as the "treasure" position. Player begins at position 0.000, 0.000. Then the game asks the player which directions to go in X and Y. After that the game needs to give the player a simple hint, if he's getting closer(right or wrong direction based on the treasure position). When the player is less than 0.050 away from treasure in any direction, the game ends and prints out the score(cycle steps).
I wrote this, but I'm getting 'Segmentation fault' and I'm also interested about how would you modify it to get it more effective and functional.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
int main()
{
srand (time(NULL));
char *direction_x;
char *direction_y;
double direction_forward;
double direction_back;
double direction_left;
double direction_right;
double score_x;
double score_y;
double diff_x;
double diff_y;
double lastmove_x;
double lastmove_y;
int i;
double random_x = (double)rand()/RAND_MAX*20.000-10.000;
double rounded_x = (int)(random_x * 1000.0)/1000.0;
printf ( "%f\n", random_x);
printf ( "%.3f\n", rounded_x);
double random_y = (double)rand()/RAND_MAX*20.000-10.000;
double rounded_y = (int)(random_y * 1000.0)/1000.0;
printf ( "%f\n", random_y);
printf ( "%.3f\n", rounded_y);
double player_x=0.000;
double player_y=0.000;
printf("Hello freind! Let's find the hidden treasure!\n");
do{
i++;
printf("Where would you want to go? ('straight', 'back')\n");
scanf("%s", &direction_x);
if (strcmp(direction_x, "straight") == 0)
{
printf("How far?\n");
scanf("%f", &direction_forward);
player_x = player_x + direction_forward;
printf("You've walked %.3f straight!\n", direction_forward);
printf("Your current postion is: %.3f, %.3f.\n", player_x, player_y);
diff_x = random_x - player_x;
if (diff_x < random_x)
{
printf("You're closer...\n");
}
else
{
printf("Don't like this way...\n");
}
}
else if (strcmp(direction_x, "back") == 0)
{
printf("How far?\n");
scanf("%f", &direction_back);
player_x = player_x - direction_back;
printf("You've walked %.3f backwards!\n", direction_back);
printf("Your current position is: %.3f, %.3f.\n", player_x, player_y);
if (diff_x < random_x)
{
printf("You're closer...\n");
}
else
{
printf("Don't like this way...\n");
}
}
else
{
printf("Don't accept this direction...\n");
}
printf("Where now? ('left', 'right')\n");
scanf("%s", &direction_y);
if (strcmp(direction_y, "left") == 0)
{
printf("How far?\n");
scanf("%f", &direction_left);
player_y = player_y + direction_left;
printf("You've walked %.3f left!\n", direction_left);
printf("Your current position is: %.3f, %.3f.\n", player_x, player_y);
if (diff_y < random_y)
{
printf("You're closer...\n");
}
else
{
printf("Don't like this way...\n");
}
}
else if (strcmp(direction_y, "right") == 0)
{
printf("How far?\n");
scanf("%f", &direction_right);
player_y = player_y - direction_right;
printf("You've walked %.3f right!\n", direction_right);
printf("Your current position is: %.3f, %.3f.\n", player_x, player_y);
if (diff_y < random_y)
{
printf("You're closer...\n");
}
else
{
printf("Don't like this way...\n");
}
}
else
{
printf("Don't accept this direction...\n");
}
score_x = (player_x + 0.050) - random_x;
score_y = (player_y + 0.050) - random_y;
}while ((-0.050 <= score_x <= 0.050) || (-0.050 <= score_y <= 0.050));
printf("Congratulations, treasure was finally founded! Treasure position is %.3f, %.3f.\n", random_x, random_y);
printf("Score (steps taken, less is better): %d\n", i);
return 0;
}
I just tried to compile your code.
First: If you use scanf() you should specify "%lf" if you want to read in a double. For example:
scanf("%lf", &direction_right);
Second: Many of your variables are not initialized. The first segmentation fault will likely be thrown at the beginning of your while-loop at this line:
scanf("%s", &direction_x);
because direction_x is not initialized it stores a pointer with a random value. This means, that it is pointing to somewhere in your memory, depending on the value previously stored at the spot where direction_x was located to. This likely causes the crash.
Avoid this by declaring an array like so.
char direction_x[42];
char direction_y[42];
But don't forget to check your input lengths!
There are many more variables you use before initializing them. Check your compilerwarnings by adding the flag -Wall (if you are using gcc).
Third: Try to structure your code. anything within a if-else statement can be put into an own function. This will help you and anyone else who tries to understand your code.
char *direction_x; and char *direction_y; should be like char st[1024] for use in scanf
i must init before use it
scanf("%s", &direction_x); should be scanf("%s", direction_x);
For double should use %lf, not %f
-0.050 <= score_x <= 0.050 should be -0.050 <= score_x && score_x <= 0.050
and so on ...
I rewrite it.
The follow code could work:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <math.h>
int main()
{
srand (time(NULL));
double random_x = (double)rand()/RAND_MAX*20.000-10.000;
double random_y = (double)rand()/RAND_MAX*20.000-10.000;
double player_x=0.000;
double player_y=0.000;
double score_x;
double score_y;
int step = 0;
printf("Hello friend! Let's find the hidden treasure!\n");
do {
step++;
char st[1024];
double data;
printf("Where would you want to go? (horizontal or vertical)\n");
scanf("%s", st);
printf("How far?\n");
scanf("%lf", &data);
if (strcmp(st, "horizontal") == 0)
{
player_x = player_x + data;
printf("You've walked %.3f left!\n", data);
printf("Your current position is: %.3f, %.3f.\n", player_x, player_y);
if (fabs(player_x - random_x) < fabs(player_x - data - random_x))
printf("You're closer...\n");
else
printf("Don't like this way...\n");
}
else if (strcmp(st, "vertical") == 0)
{
player_y = player_y + data;
printf("You've walked %.3f down!\n", data);
printf("Your current position is: %.3f, %.3f.\n", player_x, player_y);
if (fabs(player_y - random_y) < fabs(player_y - data - random_y))
printf("You're closer...\n");
else
printf("Don't like this way...\n");
} else {
continue;
}
score_x = player_x - random_x;
score_y = player_y - random_y;
} while (fabs(score_x) > 0.050 && fabs(score_y) > 0.050);
printf("Congratulations, treasure was finally founded! Treasure position is %.3f, %.3f.\n", random_x, random_y);
printf("Score (steps taken, less is better): %d\n", step);
return 0;
}
for some reason I am unable to print out "* " in my program. I want to print out * if the condition is met. the condition is if the rainfall that day is greater than the average.
under the mean column, i am getting weird symbols. i tried debugging to decimals and get -112 for ascii. i dont understand but i tried researching!
I am new to C so please be understanding. Just learned like 2 days ago!!.
Here is my code :
//Assignment one 9/20/2018
//Anthony Lomaistro and David Luong
//luongd5#student.lasalle.edu
//lomaistroa1#student.lasalle.edu
#include <stdio.h>
main() {
int n = 0; //counters for the loops
int x = 0; // counter for the loops
int counter = 0; // counter whenever i need to keep track of increments
int days_input = 0; // how many days we are keeping track of
int number_of_days = 0;
double rainfall_input = 0;
double rainfall_amount = 0; // how much rainfall per day
double rainfall_average = 0; // average of rainfall
double rainfall_total = 0;
double rainfall_counter = 0; // count how many days it rained above the average
int correct = 0;
double rainfall_array[50];//array that contains the user input
char rainfall_condition[50]; // array that contains the *
double sum = 0;
double average = 0;
double percent_days = 0; //rainfall % above average
double valid = 0;
double valid2 = 0;
printf("Welcome to Lomaistro and Luong's Rainfall Program \n");
printf("How many days would you like to keep track of? Please enter a value between 1 and 50: #%d:", n + 1);
//printf(number_of_days);
while (valid == 0) {
scanf_s("%d", &number_of_days);
if ((number_of_days > 50) || (number_of_days <= 0)) { // come back to this, this doesnt do anytihng
printf("Invalid value, please enter in a day that is between 1 and 50 \n");
}
else {
valid = 1;
}
}
//getting the user to enter in the rainfall
for (x = 0; x < number_of_days; x = x + 1) {
valid2 = 0;
while (valid2 == 0) {
printf("Enter rainfall (in inches): ");
scanf_s("%lf", &rainfall_amount);
if ((rainfall_amount >= 0) && (rainfall_amount <= 10)) {
valid2 = 1;
rainfall_array[x] = rainfall_amount;
}
else
printf("Please enter in a valid rainfall amount between 1 and 10");
}
}
//computing average
for (n = 0; n < number_of_days; n = n + 1) {
sum += rainfall_array[n];
average = sum / number_of_days;
}
printf("Mean daily rainfall(in inches): %lf", average);
//seeing if the * should be the array or not
for (n = 0; n < number_of_days; n = n + 1) {
if (rainfall_array[n] > average) {
rainfall_condition[n] = "*";
rainfall_counter = rainfall_counter + 1;
}
else
rainfall_condition[n] = "empty";
}
// print out the thing
printf("\n Days \t Amount \t >Mean \n");
printf("==============================\n");
for (n = 0; n < number_of_days; n = n + 1) {
printf("%d \t %f \t %c \n", n + 1, rainfall_array[n], rainfall_condition[n]);
}
percent_days = rainfall_counter / number_of_days;
percent_days = percent_days * 100;
printf("Number of days that rained above average : %f \n", rainfall_counter);
printf("Percentage of days that rained above average: %f%% \n", percent_days);
system("pause");
}
rainfall_condition is an array of char, but you're putting a pointer to a string literal in there when you use "*". Use '*' for a character literal instead. To be more specific, this line:
rainfall_condition[n] = "*";
Should be:
rainfall_condition[n] = '*';
Turn some warnings on in your compiler; the first line (what you have now) isn't valid C code and you should be seeing a diagnostic message to that effect.
Edit: now that I've read more of the code, it appears you want either a * or an empty in that column? In that case you want to change the variable declaration to:
char *rainfall_condition[50]; // array that contains the *
And then change the print statement to:
printf("%d \t %f \t %s \n", n + 1, rainfall_array[n], rainfall_condition[n]);
I am working in an assignment for my intro to programming class.
Here is what my professor is asking:
Change the program without adding another loop, so it determines if the grade entered is valid, and if not, display an error message and keep asking until a valid grade is entered. Change the program, so it counts how many grades scored A, B, C, D, and F. Do NOT use stacked if or if-else constructs. Do NOT use the else if format. Output a table of the count of how many there are for each letter grade.
Here is my code:
#include <stdio.h>
#include <stdlib.h>
/*Ask the user to enter 10 test scores.
The pass mark is 70%.
Calculate the average score, and count how many
of the students have passed the test.
*/
#define SCORES_COUNT 10
#define BAD_SCORE 60
#define PASSING_SCORE 70
#define GOOD_SCORE 80
#define EXCELLENT_SCORE 90
int main()
{
int scores[SCORES_COUNT];
int i, sum = 0, sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0;
for (i = 0; i < SCORES_COUNT; i++)
{
printf("Enter score for student %i: ", i + 1);
scanf("%i", &scores[i]);
if (scores[i] > 100 || scores[i] < 0)
{
printf("\n\tERROR: Invalid number! Enter a score above zero and below one hundred!\n\n");
printf("Enter score for student %i: ", i + 1);
scanf("%i", &scores[i]);
}
}
for (i = 0; i < SCORES_COUNT; i++)
{
if (scores[i] >= EXCELLENT_SCORE)
{
sum++;
}
if (scores[i] >= GOOD_SCORE && scores[i] < EXCELLENT_SCORE)
{
sum1++;
}
if (scores[i] >= PASSING_SCORE && scores[i] < GOOD_SCORE)
{
sum2++;
}
if (scores[i] >= BAD_SCORE && scores[i] < PASSING_SCORE)
{
sum3++;
}
if (scores[i] < BAD_SCORE)
{
sum4++;
}
}
printf("\nGrades Distribution\n");
printf("\nA: %i", sum);
printf("\nB: %i", sum1);
printf("\nC: %i", sum2);
printf("\nD: %i", sum3);
printf("\nF: %i\n", sum4);
system("pause");
return 0;
}
The program works fine, but my teacher told me to not use stacked if or if-else constructs. And since I am a beginner that is the only way I know how to do it.
Can somebody please tell me how can I change all the if constructs, or how can I have the same result without using any if constructs?
#include <stdio.h>
int printMenu(int);
int studentglobal;
float getCarryMark(float);
float cm1;
main()
{
printf("-----------------------------------------------------\n");
printf("\t\tTotal Score calculator\n");
printf("-----------------------------------------------------\n");
int counter, x, studentcount = 1,sum = 0 ;
x = printMenu(studentglobal);
for (counter = 0; counter < x; counter++)
{
studentcount = studentcount + counter;
printf("Student : %d \n", studentcount);
getCarryMark(cm1);
if (cm1 >= 0 && cm1 <= 50)
{
printf("right range!!\n");
}
else
{
printf("INVALID RANGE!!!\n");
}
printf("%.2f\n", cm1);
}
}
int printMenu(int nstudent)
{
printf("Enter no of student: ");
scanf("%d", &nstudent);
return(nstudent);
}
float getCarryMark(float carrymark)
{
printf("Enter your carrymarks: ");
scanf("%f", &carrymark);
return(carrymark);
}
So actually when I enter 200, it shows INVALID RANGE!!!, but when I enter 20 it still shows INVALID RANGE!!!. It somehow skipped the if statement. Please don't bother the other part, if I have any mistake tell me please. ert gf dfg dgd dg dfgd gd dg dg dgdfg
You need to return carrymark from getCarryMark:
float getCarryMark(float carrymark)
{
printf("Enter your carrymarks: ");
scanf("%f", &carrymark);
return(carrymark);
}
You are missing a return statement in getCarryMarks method !
You missed the return statement in getCarryMark
getCarryMark function takes a parameter by value, modifies the value and returns it back, however, the returned value is never used. Modifying the parameter's value does not reflect this change to the outside since it has been passed by value.
I have partially updated the code so that it could execute the if statement. Please try the following code.
#include <stdio.h>
int printMenu(int);
int studentglobal;
float getCarryMark(float);
float cm1;
main()
{
printf("-----------------------------------------------------\n");
printf("\t\tTotal Score calculator\n");
printf("-----------------------------------------------------\n");
int counter, x, studentcount = 1,sum = 0 ;
x = printMenu(studentglobal);
for (counter = 0; counter < x; counter++)
{
studentcount = studentcount + counter;
printf("Student : %d \n", studentcount);
cm1 = getCarryMark();
if (cm1 >= 0 && cm1 <= 50)
{
printf("right range!!\n");
}
else
{
printf("INVALID RANGE!!!\n");
}
printf("%.2f\n", cm1);
}
}
int printMenu(int nstudent)
{
printf("Enter no of student: ");
scanf("%d", &nstudent);
return(nstudent);
}
float getCarryMark()
{
float carrymark = 0.0;
printf("Enter your carrymarks: ");
scanf("%f", &carrymark);
return(carrymark);
}