C Programming Language: Checking Number of Subjects Chosen for a Course

In summary, the conversation discussed a task to write a C program that checks the number of subjects a student has chosen for a course. The program should run after the student updates their subject selection and if the number is less than 6, an appropriate message should be displayed. It was suggested to start with a basic code that compiles and then add necessary code to complete the task. The program should also include a function that counts the number of subjects.
  • #1
joe88
3
0
my friend i fail to perform this simple task can you please direct me how to approach a simple question like this
the quetion said "a registrar set up the curriculum for the term . One course may have up to 10 subject . Students must select a minimum of 6 subjects from a particular course .Once a student registers for the term , the billing system is notified so that the student may be billed .Student may use the system to add or drop subjects for the period of time of registration.\
write a C program that will check the number of subject s the student has chosen for a course .This program will run after the student has updated the subject selection. If the number of subject is less than 6 then an appropriate message should be displayed on the screen . The program should include a function that will count the number of subjects.
 
Technology news on Phys.org
  • #2
you start from something that compiles:
Code:
int main (void) {
  return 0;
}
and then add code as necessary.
 
  • #3


Sure, I can help you with this task. First, we need to understand the requirements of the program. The program needs to check the number of subjects a student has chosen for a course and display a message if it is less than 6. We also need to create a function that will count the number of subjects.

To start, we can declare a variable to store the number of subjects chosen by the student. Let's call it "numOfSubjects" and initialize it to 0. We can use a loop to ask the student to enter the number of subjects they have chosen and update the variable accordingly. The loop can run until the student enters a valid number (between 1 and 10).

Once the student has entered the number of subjects, we can call the function to count the number of subjects. This function can take the "numOfSubjects" variable as a parameter and return the count.

Now, we can use an if statement to check if the count is less than 6. If it is, we can display an appropriate message on the screen, such as "You have chosen less than 6 subjects. Please add more subjects to meet the minimum requirement." If the count is equal to or greater than 6, we can display a message saying "You have successfully chosen 6 or more subjects."

In addition, we can also add error handling to ensure that the student enters a valid number of subjects and display an error message if they enter an invalid number.

I hope this helps you understand how to approach this task. Remember to break down the problem into smaller steps and use appropriate data types and control structures to solve it. Good luck!
 

1. How do I check the number of subjects I have chosen for a course in C programming language?

To check the number of subjects chosen for a course in C programming language, you can use the sizeof operator. This operator returns the size of a variable in bytes, which can be used to determine the number of subjects chosen based on the data type used.

2. Can I use a loop to check the number of subjects chosen for a course in C programming language?

Yes, you can use a loop to check the number of subjects chosen for a course in C programming language. You can use a for or while loop to iterate through an array or list of subjects and count the number of elements to determine the total number of subjects chosen.

3. Is there a built-in function in C programming language to check the number of subjects chosen for a course?

No, there is no built-in function in C programming language specifically for checking the number of subjects chosen for a course. However, you can use the sizeof operator or a loop to achieve the same result.

4. What happens if I exceed the maximum number of subjects allowed for a course in C programming language?

If you exceed the maximum number of subjects allowed for a course in C programming language, you may encounter errors or unexpected behavior in your program. It is important to carefully consider the maximum number of subjects allowed and handle any potential errors in your code.

5. Can I use a conditional statement to check the number of subjects chosen for a course in C programming language?

Yes, you can use a conditional statement like if or switch to check the number of subjects chosen for a course in C programming language. You can set conditions based on the number of subjects and handle different scenarios in your program accordingly.

Similar threads

  • Programming and Computer Science
Replies
9
Views
1K
  • STEM Academic Advising
Replies
12
Views
1K
  • Sticky
  • Programming and Computer Science
Replies
13
Views
4K
Replies
6
Views
1K
  • STEM Academic Advising
Replies
11
Views
522
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
10
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
1K
Back
Top