Thread: I have a question about my project...

  1. #1
    Registered User
    Join Date
    May 2020
    Posts
    3

    I have a question about my project...

    Can someone please review my .c file and answer my question on line 24, 25.

    Thank you in advance and have a nice day!!!

    Here's a copy of my file in case it wasn't attached:
    Code:
    //This is just a rough draft of a project I am working on, so I apologize for the sloppy work..
    #include <stdio.h>
    #include <stdlib.h>
    
    
    int main (){
    
    
    
    
    float a,b,c,d,e,y,w;
    float f=3.79;
    b=100;
    e=64;
    d= f/e;
    
    
    while (a<10){
    
    
    
    
        printf("Enter your number: \n");
        scanf("%f",&c);
    
    
        w=.059219*c;
        y=d+=w;
        if(y>10){
        printf("You did it!!!!\n");
    y=y-10;//Why is the value of "y" not being subtracted from this statement?
    //When I run it, the value keeps adding from "d+=w" past the if statement.
    }
    
    
    }
    return 0;
    }
    Attached Files Attached Files
    • File Type: c hw1.c (560 Bytes, 14 views)

  2. #2
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    738
    This may or may not be related to your problem, but what is the value of "a" at this line: while (a<10){? Hint: you don't know.

  3. #3
    Registered User
    Join Date
    May 2020
    Posts
    3
    It didn't have a value. I gave it "0" but still no go...

  4. #4
    Registered User Sir Galahad's Avatar
    Join Date
    Nov 2016
    Location
    The Round Table
    Posts
    174
    Quote Originally Posted by merc824 View Post
    y=y-10;//Why is the value of "y" not being subtracted from this statement?
    Because you're effectively erasing its current value here:

    Code:
     y=d+=w;
    The power of null.

  5. #5
    Registered User
    Join Date
    May 2020
    Posts
    3
    Thank for the feedback, could you please explain why it's erasing it's value? I thought that += was adding both variables.

  6. #6
    Registered User
    Join Date
    May 2012
    Posts
    422
    Quote Originally Posted by merc824 View Post
    Thank for the feedback, could you please explain why it's erasing it's value? I thought that += was adding both variables.
    You've written
    Code:
    y = d += w;
    This doesn't make sense, and shouldn't be allowed in C, but in fact it is allowed due to historical hangovers. Break out the expression on to two lines, and then it becomes obvious what you intend.
    I'm the author of MiniBasic: How to write a script interpreter and Basic Algorithms
    Visit my website for lots of associated C programming resources.
    https://github.com/MalcolmMcLean


  7. #7
    Registered User
    Join Date
    Dec 2017
    Posts
    956
    Quote Originally Posted by Malcolm McLean View Post
    This doesn't make sense, and shouldn't be allowed in C
    You don't know what you're talking about.
    It makes perfect sense.
    Of course it should be "allowed".
    If you want the truth to stand clear before you, never be for or against. - Sent-ts'an

  8. #8
    Registered User
    Join Date
    Apr 2020
    Posts
    58
    First of all, don't attack the other users. It doesn't help you in the longrun. The only think that happens with that is anger.

    Secondly, it's not allowed in C. Where did you find it? C isn't your maths teacher.

    And lastly, who are you to judge what should be allowed in C and what not?

  9. #9
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,920
    Quote Originally Posted by TheGreekMan2000
    Secondly, it's not allowed in C. Where did you find it? C isn't your maths teacher.
    It is legal C syntax. That's the one thing both Malcolm McLean and john.c agree on, and they are right.

    Quote Originally Posted by TheGreekMan2000
    And lastly, who are you to judge what should be allowed in C and what not?
    In matters of "should or should not be allowed", programmers are entitled to their own opinions, and you'll find that we can very opinionated. That's partly why new programming languages are born!

    In matters of "what is or is not allowed", you would refer to the C standard, and then to other standards and compiler documentation where applicable.
    Last edited by laserlight; 05-30-2020 at 02:49 AM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 08-02-2013, 06:45 PM
  2. Project Euler Question
    By Head In Jar Man in forum C++ Programming
    Replies: 6
    Last Post: 04-26-2009, 02:59 PM
  3. MSVC project question
    By l2u in forum Windows Programming
    Replies: 2
    Last Post: 03-28-2007, 10:45 AM
  4. my first project, A question
    By C+noob in forum C++ Programming
    Replies: 29
    Last Post: 07-07-2005, 12:19 AM
  5. VS .net project setting question
    By Jumper in forum C++ Programming
    Replies: 1
    Last Post: 05-13-2004, 11:03 AM

Tags for this Thread