7 hours?

This is a discussion on 7 hours? within the C Programming forums, part of the General Programming Boards category; Hello I have a project, and I just need the next push in this code. I'm not sure how to ...

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    1

    7 hours?

    Hello I have a project, and I just need the next push in this code. I'm not sure how to tell the program that it can't exceed 7 credit hours? Thanks

    At Valence community college, a student canít take more than 3 courses under the constraint of having no more than 7 credit hours. The purpose of this assignment is to construct a fee invoice for a student. This requires the input of Studentís id as integer and the course numbers.
    It costs 120.25 dollars per credit hour in addition to $35.00 charged for health and id services.

    Here is the list of all courses Valence Community College offers:

    CRN Course Prefix Credit Hours
    4587 MAT 236 4
    4599 COP 220 3
    8997 GOL 124 1
    9696 COP 100 3
    4580 MAC 236 2
    4591 CLP 229 5
    9997 GGG 124 0
    9693 CMP 100 4


    After inputting all the necessary data (see sample run), a fee invoice as shown below should be printed to the screen.

    VALENCE COMMUNITY COLLEGE
    ORLANDO FL 10101
    ---------------------

    Fee Invoice Prepared for Student V5656

    1 Credit Hour = $120.25

    CRN CR_PREFIX CR_HOURS
    4587 MAT 236 4 $ 481.00
    4599 COP 220 3 $ 360.75

    Health & id fees $ 35.00

    --------------------------------------
    Total Payments $ 876.75



    ASSUME THAT THE USER WILL ALWAYS ENTER DISTINCT VALID COURSE NUMBERS

    Sample Run (The userís entry is in bold)

    Enter the Students Id
    5656

    Enter how many courses-up to 3
    6
    Invalid number! Try again

    Enter how many courses-up to 3
    3

    Enter the 3 course number(s)
    4587 4599 9696

    Sorry, you canít cumulate more than 7 credit hours

    Do you want to try again (Y/N)
    y

    Enter how many courses-up to 3
    2

    Enter the 2 course number(s)
    4587 4599

    Thank you!
    Press Any Key to Continue


    VALENCE COMMUNITY COLLEGE
    ORLANDO FL 10101
    ---------------------

    Fee Invoice Prepared for Student V5656

    1 Credit Hour = $120.25

    CRN CR_PREFIX CR_HOURS
    4588 MAT 236 4 $ 481.00
    4599 COP 220 3 $ 360.75

    Health & id fees $ 35.00

    --------------------------------------
    Total Payments $ 876.75





    Goodbye!

    Code:
    #include <stdio.h>
    
    int main ()
    {
    int studentID = 0, courseTotal = 0;
    
    
    
       printf("Enter the Student ID: ");
       scanf("%d", &studentID);
       
       printf("Enter how many courses - up to 3: ");
       scanf("%d", &courseTotal);
       
       while ( courseTotal > 3 || courseTotal < 1)
       {
             printf ("Invalid number! Try again\n\n");
       
             printf("Enter how many courses - up to 3: ");
             scanf("%d", &courseTotal);
       }
    
    printf ("\n\nEnter the %d course number(s)\n\n", courseTotal);
       
       
              
              system ("pause");

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,546
    > CRN Course Prefix Credit Hours
    > 4587 MAT 236 4
    Are you meant to read this information from a file, or is it hard coded in the source code?

    Do you know about
    - arrays
    - structures
    ?

    If you do, then I would suggest you declare a struct containing the relevant information, then declare an array of that struct (of suitable length), and have a go at reading the file.

    After that, write a function that takes a course ID as a parameter, then returns the corresponding credit hours as the result.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. secs into hours mins and remainin secs
    By manzoor in forum C++ Programming
    Replies: 2
    Last Post: 01-12-2008, 12:21 PM
  2. Academic
    By kirksson in forum C Programming
    Replies: 6
    Last Post: 10-27-2007, 01:07 PM
  3. Functions and Structs...
    By pandroff in forum C Programming
    Replies: 1
    Last Post: 12-03-2005, 04:12 PM
  4. Time between Military Hours
    By StarOrbs in forum C++ Programming
    Replies: 18
    Last Post: 03-01-2005, 05:46 PM
  5. My final data does not display
    By p1c1078 in forum C Programming
    Replies: 3
    Last Post: 04-23-2003, 06:32 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21