Computer problems,Computer help
*AX SOFT>>>Programming & Design

Can you tell me what is my mistake, and how can i fix it?


yeah hello guyz, i need your help with something. this is what i am trying to figure out "table of fractions and their decimal equivalents, rounded to 3 decimal positions."
it should be like this
1/2 = 0.500
1/3 = 0.333
1/4 = 0.250
1/5 = 0.200
1/6 = 0.167
......
1/20 = 0.050
and then it should end. i have the code but i don't what is the problem. i have one warning though if it is important. i am done with most of the code and now i don't know what is going on.
here's my code...
int num = 1;
float result;
int Fraction_Table;
cout << " Fraction Table " << endl;
cin >> Fraction_Table;
while (num < 20)

result = 1/num;
cout << " \n1/ " << num << " = " << result ;
cout << "\nThe End";
please help

I don't quite see what you are doing with the whole cin bit etc. I'll make you a MUCH improved code ;)

float ans;

for(float i=1;i<=20;i++){
ans = 1/i;
cout << "1/" << i << " = " << ans << endl;
if(i==20) break;
}
cin.get();
return 0;

What exactly is the Fraction_Table variable doing? Other than that, I'd say wrap the statements you want in the loop in brackets, increment your num variable, type cast num as a float in your assignment to result and use <iomanip> if you want to format the decimals.

Looks like you need to increment num

while (num < 20)
{
result = 1/num;
cout << " \n1/ " << num << " = " << result ;
num++;
}
cout << "\nThe End";

Tags
  General - Computers & Internet   Software   Security   Programming & Design   Facebook   Flickr   Google   MSN   MySpace
Related information
  • Could someone please tell me the average salary of Yahoo, Bangalore for a person having 2.5 years or IT exp?

    well if you work for me (pennsylvania) 2 years exp no certifications such as A+ i would pay you around 10.00 a hour so called IT techs are a dime a dozen

    ...
  • Select me good title for my final year project.?

    May be you can search at project assignment website like ...

  • How to code a java picture?

    There are a number of ways to do this. The solution depends on if you're wanting to use AWT, Graphics2D, JFC Swing, or even a non-standard library. The shortest number of code lines would ...

  • I can't edit my freewebs site!?

    Need to know how you are saving it. Are you using the FreeWebs online Visual/Text Editor then clicking the Save icon or are you trying to save your page from your browser via the File, Save Page a...

  • Where i can creat my own web for free? :)?

    Setting up a Web site is very easy and if you want to do it for free just go to ...

  • How can I get the value inside an <option></option> tag on a select box using javascript?

    Use the DOM! :) <script type="text/javascript"> var sel = document.getElementById("MySelectBox") var optVal = sel.options[<position of option, base 0>].text &l...

  • Is there a service where i can create my own Im system?

    Yes, you could host your own Jabber instant messaging server (see ...

  • Align Text ?

    You may have whitespace appearing in your code or a line break of some kind. Really need to see the code you used. As a safety note, not a good idea to put personal information on a web page......

  •  

    Categories--Copyright/IP Policy--Contact Webmaster