October 30th, 2007, 01:00 PM  #1 
Newbie Joined: Oct 2007 Posts: 24 Thanks: 0  C++ help (beginner)
In the past half hour, I've started learning C++. As a project, I decided to try and write a program that will turn a fraction into a percentage. Here is my code: Code: #include <iostream> using namespace std; int main() { int numerator, denominator, quotient; cout << "Percentage Calculator\n"; cin.get(); cout << "Enter numerator: "; cin >> numerator; cout << "\nEnter denominator: "; cin >> denominator; cin.get(); cout << numerator << "/" << denominator << " = "; quotient = numerator/denominator; cout << quotient * 100 << "%"; cin.get(); } For some reason it doesn't like the division, could anyone tell me what I'm doing wrong? Thanks 
October 30th, 2007, 01:07 PM  #2 
Senior Member Joined: May 2007 Posts: 402 Thanks: 0 
Of course it doesn't work since your quotient variable is set to integer, and therefore cannot have a float value! What you need to do is replace the following: (1) int numerator, denominator, quotient; with int numerator, denominator; float quotient; (2) quotient = numerator/denominator; with quotient = (float)numerator/denominator; Now it should work! 
October 30th, 2007, 02:32 PM  #3 
Newbie Joined: Oct 2007 Posts: 24 Thanks: 0 
Thanks very much, I really should've thought of that Thank you 

Tags 
beginner 
Thread Tools  
Display Modes  

Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Beginner's dilemma  shunya  Computer Science  3  November 27th, 2013 10:54 AM 
I'm a beginner, need urgent help with 3 problems  J8m  Algebra  0  February 24th, 2013 06:21 AM 
beginner's book  Peter1107  Calculus  6  August 2nd, 2011 09:23 AM 
Help plz with VERY beginner limits.  NathanielZhu  Calculus  7  August 1st, 2010 05:17 PM 
Calculus1 beginner  prathimarao  Algebra  7  June 10th, 2009 08:26 PM 