Thread: A Little Help

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    11

    A Little Help

    First off I'm looking for help not someone to do it for me.

    My first assignment is: There are 2 midterms, each counting 20% of the grade. The final is worth 25%, and there are 5 programming assignments each worth 7%. Write a program that will prompt the user to enter the grade received on each of these parts (each on a scale of 0.0 - 10.0) and will calculate the final grade in the course.


    My second assignment is: Now modify the program in part on as follows. The student is about to take the final exam in the course and would like to know the minimum score they need to get to receive a specific grade. Modify the program to prompt the user for the desired numerical grade (0 - 100.0) and will calculate the grade needed on the final to active the desired result.

    This is what I have so far:
    Code:
    #include <stdio.h>
    
    int main(int argc, char* argv[])
    {
      int assignment1;
      int assignment2;
      int assignment3;
      int assignment4;
      int assignment5;
      int midterm1;
      int midterm2;
      int final;
      float numeric;
      
      
      printf("Enter assignment1: ");
      scanf("%d", &assignment1);
      printf("Enter assignment2: ");
      scanf("%d", &assignment2);
      printf("Enter assignment3: ");
      scanf("%d", &assignment3);
      printf("Enter assignment4: ");
      scanf("%d", &assignment4);
      printf("Enter assignment5: ");
      scanf("%d", &assignment5);
    
    
    
      printf("Enter midterm1: ");
      scanf("%d", &midterm1);
      printf("Enter midterm2: ");
      scanf("%d", &midterm2);
    
      printf("Enter final: ");
      scanf("%d", &final);
    
      numeric = ((((assignment1 + assignment2 + assignment3 + assignment4 + assignment5) * .07) + (midterm1 + midterm2) * 0.20) + (final * 0.25));
      printf("%d/%d/%d/%d/%d/%d/%d/%d\n", assignment1, assignment2, assignment3, assignment4, assignment5, midterm1, midterm2, final);
    
      return 0;
    }

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Would you like to ask a question?

  3. #3
    Registered User
    Join Date
    Feb 2012
    Posts
    11
    Yeah what am i missing to make it add each one together. the code u see work but it give me 10/10/10/10/10/10/10/10

  4. #4
    Registered User
    Join Date
    Feb 2012
    Posts
    11
    Am I on the right path so far...

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    each on a scale of 0.0 - 10.0
    Those don't look like whole numbers to me. Int's are whole numbers, only.

    So no, wrong path there.

  6. #6
    Registered User
    Join Date
    Feb 2012
    Posts
    11
    So all my int's r wrong

  7. #7
    Registered User
    Join Date
    Feb 2012
    Posts
    11
    I've tried changing %d to %1f and %f and all bad commands

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Does 0.07 * 3.5 (for instance), sound like a whole number, to you?

    Did you change the data type?

    Honestly, I know it's English you're posting, but I need to see some code here. I could ramble on for days, and completely miss the problem, without seeing the code.
    Last edited by Adak; 02-11-2012 at 05:24 PM.

  9. #9
    Registered User
    Join Date
    Feb 2012
    Posts
    11
    That my problem I don't see what I'm missing. I don't know what I have to change you said int but to what the class I'm in we haven't been taut anything but int so far. This is not my first program.
    Code:
     
    
    #import <stdio.h>
    
    
    int main(void){
      int n;
      printf("Enter a number between 0 and 32767: ");
      scanf("%d", &n);
    
    
      int octal_1, octal_2, octal_3, octal_4, octal_5;
    
    
      octal_1 = ((((n / 8) / 8) / 8) / 8) % 8;
      octal_2 = (((n / 8) / 8) / 8) % 8;
      octal_3 = ((n / 8) / 8) % 8;
      octal_4 = (n / 8) % 8;
      octal_5 = n % 8;
      
      printf("In octal, your number is: %d%d%d%d%d\n", octal_1, octal_2, octal_3, octal_4, octal_5);
      return 0;
    }
    This one I did and I didn't have a problem.
    I'm not stupid just NEW...

  10. #10
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    That my problem I don't see what I'm missing. I don't know what I have to change you said int but to what the class I'm in we haven't been taut anything but int so far. This is not my first program.
    So, you used "float" in your program and you have no idea what it does?

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  11. #11
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Your original program had a float in it. So I thought you knew about using a floating point data type for variables holding something other than whole numbers.

    For most purposes, I prefer doubles to floats, since they give greater accuracy than float types. I'd use double data types, instead of int's.

    I never said you were stupid - just that I can't tell from a description, the details of a program that you have changed, but not posted yet.

    Since you can print decimal values as octal values, immediately, I don't see the purpose to your octal program, at all. Octal is a printf() standard format specification.

  12. #12
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    You're never printing out the (strangely named) variable numeric.
    Add this before return 0;
    Code:
    printf("%f\n", numeric);

  13. #13
    Registered User
    Join Date
    Feb 2012
    Posts
    11
    So with this added
    Code:
    printf("%f\n", numeric);
    It gives me and average score. My code now looks like this
    Code:
    #include <stdio.h>
    #include <math.h>
    
    
    int main(int argc, char* argv[])
    {
      int assignment1;
      int assignment2;
      int assignment3;
      int assignment4;
      int assignment5;
      int midterm1;
      int midterm2;
      int final;
      float numeric;
      
    
       
      printf("Enter assignment1: ");
      scanf("%d", &assignment1);
      printf("Enter assignment2: ");
      scanf("%d", &assignment2);
      printf("Enter assignment3: ");
      scanf("%d", &assignment3);
      printf("Enter assignment4: ");
      scanf("%d", &assignment4);
      printf("Enter assignment5: ");
      scanf("%d", &assignment5);
    
    
    
      printf("Enter midterm1: ");
      scanf("%d", &midterm1);
      printf("Enter midterm2: ");
      scanf("%d", &midterm2);
    
      printf("Enter final: ");
      scanf("%d", &final);
      
    
      numeric = ((((assignment1 + assignment2 + assignment3 + assignment4 + assignment5) *.07) + (midterm1 + midterm2) *0.20) + (final * 0.25));
      printf("%f\n", numeric);
    
      return 0;
    }

  14. #14
    Registered User
    Join Date
    Feb 2012
    Posts
    11
    It gives me an average not a total what might I change to fix this.

  15. #15
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    1. Create a variable to hold the "total".
    2. Calculate the total and place it in the variable in step 1.
    3. Print out the value of the variable in step 1.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed