school project help

This is a discussion on school project help within the C Programming forums, part of the General Programming Boards category; for my shcool project, i am supposed to write a console application program where you can enter a fraction in ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    2

    school project help

    for my shcool project, i am supposed to write a console application program where you can enter a fraction in the form of n/d (numberator/denominator). then when you enter that, the program is supposed to divide the numerator by the denominator. then the prog should give you the quotient, but if it is a repeating decimal (i would just assume that anything above 8 decimal places is repeating) the program is supposed to show the repeating quotient as follows. lets say you typed in one third which is a repeating .3
    it should display it as .(3)

    1/3 [ENTER]
    .(3)

    how do you get the string input in the beginning to recognize n/d as two integers and then how do you get it to display a repeating decimal like .(3) I'm not sure how to get it to display it with the decimal point and then the parenthesis

    now im tired from typing such a long thread. i feel like a noob

  2. #2
    ggs
    ggs is offline
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435
    in your shoes, i would eat up the n/d with fgets and parse it into two strings, n and d - then use atoi to convert them to integers

    the repeating decimal place will be tricky to deal with, but sprintf and %f will likely be your friend in this
    .sect signature

  3. #3
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    University of Waterloo
    Posts
    1,903
    I feel like I recognize this question from another post somewhere on these boards.....possibly same class?

    Anyway, just to clarify:
    http://cboard.cprogramming.com/annou...ouncementid=51
    See #9

  4. #4
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    repeating decimals wouldn't be hard and you could prove it not just out 8 decimals. If your remainder after division stays the same twice in a row it is repeating
    1/3

    10/3 = 3 remainder 1 carry decimal 10 10/3 remainder 1

  5. #5
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Quote Originally Posted by linuxdude
    repeating decimals wouldn't be hard and you could prove it not just out 8 decimals. If your remainder after division stays the same twice in a row it is repeating
    1/3

    10/3 = 3 remainder 1 carry decimal 10 10/3 remainder 1
    its not nessecarily twice in a row; for example what about 1/17?
    hello, internet!

  6. #6
    Registered User
    Join Date
    Sep 2004
    Posts
    2
    haha yeah, you recognize it alright! Joeshmoe1337 is my classmate and best friend, we had no idea we were both posting the same thing lol. don't worry, the project is totally extracurricular, no grades involved
    Last edited by yogai; 09-09-2004 at 05:06 PM.

  7. #7
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    what about 1/ 17 do you mean the double 8 in it
    Code:
    0.058823529
    the numbers are the same but 150/17 then the next 8 is 140/17 different remainers

  8. #8
    moi
    moi is offline
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Quote Originally Posted by linuxdude
    what about 1/ 17 do you mean the double 8 in it
    Code:
    0.058823529
    the numbers are the same but 150/17 then the next 8 is 140/17 different remainers
    i mean your statement that when you see the same remainder twice in a row, you have found a repeater. 1/17 does repeat, but it never has the same remainder two times in a row (right next to eachother).
    hello, internet!

  9. #9
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    oh whoops I forgot about more than one digit! Oh well. I forgot about fractions like 12344/9999 I was thinking like 2/9

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Displaying a Struct
    By rockstarpirate in forum C++ Programming
    Replies: 16
    Last Post: 05-05-2008, 09:05 AM
  2. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 07:41 PM
  3. Please, suggest a project .
    By Dragon227Slayer in forum Tech Board
    Replies: 1
    Last Post: 06-12-2004, 10:48 AM
  4. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 01:58 AM
  5. Question about going to a technical school
    By Goalie35 in forum C++ Programming
    Replies: 1
    Last Post: 08-30-2001, 11:34 AM

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