Thread: Rule of 72 Code Help plz

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    7

    Question Rule of 72 Code Help plz

    plz heal me solves this error i cant get the right answer...


    #include <stdio.h>
    #include <math.h>

    void main()
    {
    int i, math, actual;

    printf("Assignment #3 Rule of 72\n");
    printf("Time it takes for prices to double due to inflation.\n\n");
    printf("Interst\t Rule\n");
    printf("Rate(%%)\t of 72 \t Actual\n\n");
    for (i=1; i<21; i++ ){
    math = 72/i;
    actual = 10;


    while(actual <= 2*10);
    actual +=(actual)*(i/100);
    printf("%d\t %d\t %d\n", i, math, actual);

    }
    }

  2. #2
    Registered User
    Join Date
    Jan 2003
    Posts
    7

    Talking

    LOL my apologies didnt read the READ THIS BEFOR U POST CODE THREAD lol

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by wnight77
    LOL my apologies didnt read the READ THIS BEFOR U POST CODE THREAD lol
    Then edit your post, and put the code tags on

    And whilst you're at it, get rid of void main, it should be int main(void) with a return at the end of it.

    >>plz heal me solves this error
    What error? You need to describe your problem.


    [edit]
    >>while(actual <= 2*10);
    Get rid of the trailing semi-colon.

    >>actual += (actual) * (i / 100);
    Think that one through again. Hint: 1/100 = ??
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Registered User
    Join Date
    Jan 2003
    Posts
    7
    void main is the same as return 0 my instructor wants me to use void main instead of return 0

    now the problem im having is... i need to have this display 3 colums of information and its not working correctly i think its my equation but i dont know... the easyest way to see this would be to write in real quick <takes liek 15 seconds> then run it it looks like this when its semi working

    Code:
    /*interest      rule
    rate(%)      of 72       actual
    
    1                72            this is the messed up colum
    2                numbers from equation
    3
    4
    5
    6
    7
    8
    9
    down to 20
    */
    Code:
     /*
    
    #include <stdio.h>
    #include <math.h>
    
    void main()
    {
    	int i,/*is the inteest rate*/ math,/*is the amount of time befor the amount double in years accourding to the 72/r ruel r= i in my case*/ actual/* amount using a more precise calculation*/;
    	
    	printf("Assignment #3 Rule of 72\n");
    	printf("Time it takes for prices to double due to inflation.\n\n");
    	printf("Interst\t Rule\n");
    	printf("Rate(%%)\t of 72 \t Actual\n\n");
    	for (i=1; i<21; i++ ){
    		math = 72/i;
    		actual = 10;
    		
    		
    		
    		while(actual <= 2*10);
    		actual +=(actual)*(1+i/100);
    		printf("%d\t %d\t %d\n", i, math, actual);	
    
    }
    }*/
    Last edited by wnight77; 01-31-2003 at 04:35 PM.

  5. #5
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>void main is the same as return 0 my instructor wants me to use void main instead of return 0
    No, its not. Do a search, or read the FAQ if you want to know more.

    Did you see my edits in my previous post?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  6. #6
    Registered User
    Join Date
    Jan 2003
    Posts
    7
    ok i see edits now im trying it but my teacher wants me to use void main i dont know what it affects is jtu know thats what i gota do to get my points hehe =)


    also its

    actual = actual + (i/100 )*(actual)

    i got thaat equation from my buddy that has it working so did i do seomthing wrong???
    Last edited by wnight77; 01-31-2003 at 04:19 PM.

  7. #7
    Registered User
    Join Date
    Jan 2003
    Posts
    7
    ohhh man look sliek imma get massive points docked off on this one yucky

  8. #8
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>i/100
    You need to learn about ints and floats.

    An int holds a whole number only, so if you do division like 1/100, which would normally be .01, the answer in C is 0 if you are using ints. A float can hold a number with precision, eg 10.12

    Have a think about where you need to apply this, and see what you come up with. As a starter (this one isn't obvious), you can use i/100.0 to force that part of the equasion to think in float terms.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  9. #9
    Registered User
    Join Date
    Jan 2003
    Posts
    7
    yeah i want the answer to come out as a hole number so ill try the .0 good idea.

    also ill put a // on all my stuff to explain it

  10. #10
    Registered User
    Join Date
    Jan 2003
    Posts
    7
    lol i think ill hand in what i have so far im really close to the answer jsut dont have the correct numbers ;p thnx for ur help man il stil get a B this is liek the 2nd assignment in my class im stil a n00b =)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-21-2006, 07:52 AM
  2. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 12:38 PM
  3. Replies: 9
    Last Post: 10-18-2004, 09:14 AM
  4. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM