Thread: variable is saving the wrong value

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

    variable is saving the wrong value

    Hello, I'm in my first class about C and I need some help with this problem please.


    The code is not getting the expected value in variable twoHundredFiftyScholarship.

    When using the debugger I can see that the only value that is incorrect is for variable [tag]twoHundredFiftyScholarship[/tag].
    The expected value for variable [tag]twoHundredFiftyScholarship[/tag] when entering the sample run #1 should be 1. The value I get is 3.
    same thing with for sample run #2. The expected value is 8. The value I get is 48.

    Could someone guide me toward the right direction please? I'm kind of confused on why this is happening and I'm stuck. Thank you!




    Code:
    
       
    
        if(thousandScholarships > 5){
            thousandScholarships = 5;
    
    
            remainingScholarship -= thousandScholarships*1000.0;}
    
    
    
    
        if(fiveHundredScholarship > 10){
            fiveHundredScholarship = 10;
    
    
            remainingScholarship -= fiveHundredScholarship*500;}
    
    
            
    
    
            remainingScholarship -= twoHundredFiftyScholarship*250;
    
    
            
    
    
                    
        
    
    
        system("pause");
        
        return 0;
    }
    Last edited by shroom; 05-27-2020 at 02:11 PM.

  2. #2
    Registered User
    Join Date
    May 2020
    Posts
    2
    I have fixed the problem by deleting the brackets before if and moving
    Code:
    twoHundredFiftyScholarship = remainingScholarship/250.0;
    to a different location.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Wrong variable value assigned
    By drag0n69 in forum C Programming
    Replies: 29
    Last Post: 02-29-2008, 03:49 PM
  2. Saving Variable File Name
    By Apocalyptic_end in forum C++ Programming
    Replies: 9
    Last Post: 01-27-2008, 09:46 AM
  3. Saving a Variable???
    By almo89 in forum C Programming
    Replies: 3
    Last Post: 02-15-2006, 08:22 PM
  4. Reading lines from a file and saving to a variable
    By Rare177 in forum C Programming
    Replies: 1
    Last Post: 06-09-2004, 03:47 PM
  5. what is wrong with this way in saving struct...,
    By mickey in forum C++ Programming
    Replies: 9
    Last Post: 05-10-2002, 02:35 AM

Tags for this Thread