14 Replies - 3178 Views - Last Post: 30 June 2013 - 11:02 AM Rate Topic: -----

#1 sudoshell   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 9
  • Joined: 29-June 13

Program capture marks and calculate highest lowest and average

Posted 29 June 2013 - 10:20 AM

#include <stdio.h>
main()
{
float higestMark, lowestMark, markSum;
int count = 0;


printf("Program to capture Marks for computer programming class (Marks range : 0 - 100)\n");
printf("Please enter q or Q to end the marks entry!\n\n");
printf("Marks for computer programming class:\n");
printf("=========================================\n\n");


if (mark < lowestMark)
{
lowestMark = mark;
}

else if (mark > highestMark)
{
highestMark = mark;

markSum += mark;
printf("%d. %.2f\n"), ++count,mark);
}

else
{
printf("Invalid Marks! marks should be between 0 and 100\n");
}


printf("\nThe following are the summary\n");
printf("-----------------------------------"\n\n);
printf("Highest mark of the class : %.2f\n", highestMark);
printf("Lowest mark of the class: %.2f\n", lowestMark);
printf("Average mark of the class : %.2f\n", markSum / count);





Help me with this! coding and validation.
i am kinda new to C programing language
help me to code simplest way it can
:rolleyes2:

Is This A Good Question/Topic? 0
  • +

Replies To: Program capture marks and calculate highest lowest and average

#2 jimblumberg   User is offline

  • member icon

Reputation: 5487
  • View blog
  • Posts: 17,063
  • Joined: 25-December 09

Re: Program capture marks and calculate highest lowest and average

Posted 29 June 2013 - 10:28 AM

Do you have a question or problem with your code?

I recommend you find an indentation style and use it consistently. This will make reading your program much easier.

And in a C program main should be defined to return an int and you should return an int from this function.
int main(void)
{

   return 0;
}


Jim
Was This Post Helpful? 0
  • +
  • -

#3 sudoshell   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 9
  • Joined: 29-June 13

Re: Program capture marks and calculate highest lowest and average

Posted 29 June 2013 - 10:28 AM

Posted Image

this is how i want help me to improve my coding
Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg   User is offline

  • member icon

Reputation: 5487
  • View blog
  • Posts: 17,063
  • Joined: 25-December 09

Re: Program capture marks and calculate highest lowest and average

Posted 29 June 2013 - 10:32 AM

So you've given us your assignment, but you need to tell us what is wrong with your program. This is your assignment, not ours. We won't write it for you, we'll help you solve problems with the code but you need to ask specific questions.

Jim
Was This Post Helpful? 0
  • +
  • -

#5 sudoshell   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 9
  • Joined: 29-June 13

Re: Program capture marks and calculate highest lowest and average

Posted 29 June 2013 - 10:36 AM

how to use q or Q to end the marks entry! if i created a loop and what happens if i enter something other then q :dontgetit:
Was This Post Helpful? 0
  • +
  • -

#6 jimblumberg   User is offline

  • member icon

Reputation: 5487
  • View blog
  • Posts: 17,063
  • Joined: 25-December 09

Re: Program capture marks and calculate highest lowest and average

Posted 29 June 2013 - 10:46 AM

Where have you created a loop? There doesn't appear to be any loops in the code you provided. Perhaps you posted the wrong code?

Also be sure to properly indent your code before posting.

Jim
Was This Post Helpful? 0
  • +
  • -

#7 vividexstance   User is offline

  • Tiocfaidh r l
  • member icon

Reputation: 792
  • View blog
  • Posts: 2,873
  • Joined: 31-December 10

Re: Program capture marks and calculate highest lowest and average

Posted 29 June 2013 - 10:49 AM

You need to start by getting input from the user, scanf() would be the function you need to call. If I have a simple program that I want it to run more than once instead of just exiting. I just use char variable, and I use a while loop to check the value of that char variable. At the end of the loop, you would ask the user if they want to continue or exit, if they input 'y' or 'Y' for yes, then the loop exits. Here's a simple example:
char ans = 'y';

while(ans == 'y' || ans == 'Y')
{
    /* Do whatever work the program needs to do... */
    
    printf("\nTry Again?(y/n): ");
    scanf("%c", &ans);
}


The first argument to the scanf() is similar to the first argument to printf. You specify the type of the data you want to input, and then the second argument needs to know where to put that data so it must be a pointer to a variable. The '&' operator takes the address of a variable if the '&' comes right before a variable name.

This post has been edited by vividexstance: 29 June 2013 - 10:49 AM

Was This Post Helpful? 1
  • +
  • -

#8 sudoshell   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 9
  • Joined: 29-June 13

Re: Program capture marks and calculate highest lowest and average

Posted 29 June 2013 - 10:56 AM

View Postvividexstance, on 29 June 2013 - 10:49 AM, said:

You need to start by getting input from the user, scanf() would be the function you need to call. If I have a simple program that I want it to run more than once instead of just exiting. I just use char variable, and I use a while loop to check the value of that char variable. At the end of the loop, you would ask the user if they want to continue or exit, if they input 'y' or 'Y' for yes, then the loop exits. Here's a simple example:
char ans = 'y';

while(ans == 'y' || ans == 'Y')
{
    /* Do whatever work the program needs to do... */
    
    printf("\nTry Again?(y/n): ");
    scanf("%c", &ans);
}


The first argument to the scanf() is similar to the first argument to printf. You specify the type of the data you want to input, and then the second argument needs to know where to put that data so it must be a pointer to a variable. The '&' operator takes the address of a variable if the '&' comes right before a variable name.




thanks :bigsmile:
okey i will show you the final coding of mine once i am done!
if i have any question during the coding i will post here! :bigsmile:
Was This Post Helpful? 0
  • +
  • -

#9 sudoshell   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 9
  • Joined: 29-June 13

Re: Program capture marks and calculate highest lowest and average

Posted 29 June 2013 - 11:46 AM

how do i limit the number between 1 - 100?
Was This Post Helpful? -1
  • +
  • -

#10 jimblumberg   User is offline

  • member icon

Reputation: 5487
  • View blog
  • Posts: 17,063
  • Joined: 25-December 09

Re: Program capture marks and calculate highest lowest and average

Posted 29 June 2013 - 11:51 AM

What have you tried? You seem to know how to use if statements, if that first post was actually written by you. So show what you've tried.

Jim
Was This Post Helpful? 0
  • +
  • -

#11 sudoshell   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 9
  • Joined: 29-June 13

Re: Program capture marks and calculate highest lowest and average

Posted 29 June 2013 - 12:13 PM

Code:
Posted Image

Output:
Posted Image


my loop is not working!
i am not good at loops
i know very well about if else statement
Was This Post Helpful? 0
  • +
  • -

#12 jimblumberg   User is offline

  • member icon

Reputation: 5487
  • View blog
  • Posts: 17,063
  • Joined: 25-December 09

Re: Program capture marks and calculate highest lowest and average

Posted 29 June 2013 - 12:21 PM

You need to cut and paste your code into the post, like you did in the first post. I can't read or compile a picture.

You may want to also study the following link: Control Structures.

Jim

This post has been edited by jimblumberg: 29 June 2013 - 12:23 PM

Was This Post Helpful? 0
  • +
  • -

#13 sudoshell   User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 9
  • Joined: 29-June 13

Re: Program capture marks and calculate highest lowest and average

Posted 29 June 2013 - 12:23 PM

#include <stdio.h>
int main()
{
	float highestMark, lowestMark, markSum, mark;
	char quit = 'y';
	int count = 0;
	 
	 
	    printf("Program to capture Marks for computer programming class (Marks range : 0 - 100)\n");
	    printf("Please enter q or Q to end the marks entry!\n\n");
	    printf("Marks for computer programming class:\n");	printf("=========================================\n\n");
// while (quit == 'y' || quit == 'Y')

		 
	if (mark >=0 && mark <=100)
	{
		if (mark< lowestMark)
		lowestMark = mark;
		markSum += mark;
		printf("%d. %.2f\n", ++count, mark);
	
	}
	 
	else if (mark > highestMark)
	{
	highestMark = mark;
	 
	markSum += mark;
	printf("%d. %.2f\n", ++count,mark);
	}
	 
	else
	{
	printf("Invalid Marks! marks should be between 0 and 100\n");
	}

	 
	    printf("\nThe following are the summary\n");
	printf("-----------------------------------\n\n");
	    printf("Highest mark of the class : %.2f\n", highestMark);
	    printf("Lowest mark of the class  : %.2f\n", lowestMark);
	    printf("Average mark of the class : %.2f\n", markSum / count);
	    getch();
	}
	


Was This Post Helpful? 0
  • +
  • -

#14 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12316
  • View blog
  • Posts: 45,416
  • Joined: 27-December 08

Re: Program capture marks and calculate highest lowest and average

Posted 29 June 2013 - 01:33 PM

And what's wrong with your code? Please ask specific questions that people can answer. Provide us with all the information we need upfront so we don't have to keep asking you for it.
Was This Post Helpful? 0
  • +
  • -

#15 vividexstance   User is offline

  • Tiocfaidh r l
  • member icon

Reputation: 792
  • View blog
  • Posts: 2,873
  • Joined: 31-December 10

Re: Program capture marks and calculate highest lowest and average

Posted 30 June 2013 - 11:02 AM

The problem is that you're trying to use the variable mark before it has been initialized. That's the reason in my code I set the ans variable to 'y' before I used it. Also, I don't see anywhere in your program where you actually get input from the user by calling the scanf() function.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1