need help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • blamp
    New Member
    • Oct 2008
    • 4

    need help

    Im writing a fraction calculator program I finished the program but keep getting an error on the do while function. can someone help

    heres the program
    Code:
    #include <iostream>  
    #include <iomanip>  
    #include <cmath>
    
    using namespace std;    // Internal storage 
    
    int choice;    
    int num1;      
    int denom1;      
    int num2;    
    int denom2;    
    int calcden;    
    int calcnum;      
    
    void menuFunction(void)
    {
      int denominator1, numerator1,denominator2, numerator2;
      char operation;
      cout<<"This program will agther your input, and perform mathematical operations on fractions. you will be prompted to enter a denominator and numerator for two fractions, and hen will be asked to enter an operation you wish to perform"<<endl;
      cout<<"Please enter the first numerator"<<endl;
      cin>>numerator1;
      cout<<"Please enter the first denominator"<<endl;
      cin>>denominator1;
      cout<<"Please enter the second numerator"<<endl;
      cin>>numerator1;
      cout<<"Please enter the second denominator"<<endl;
      cin>>denominator2;
      cout<<"You may choose aadition (+), subtraction (-), multiplication (*) or division (/)...please choose an operation:"<<endl;
     cin>>operation;
     //perform error checking, call other functions, etc...
    }
    
    void add()    
    {
    calcnum=num1*denom2 + denom1*num2;    
    calcden=denom1*denom2;    
    }
    void subtract()        
    {
        calcnum=num1*denom2-(denom1*num2);  
        calcden=calcden=denom1*denom2;  
    }
    
    void multiply()        
    {
        calcnum= num1*num2;      
        calcden=denom1 * denom2;      
    }
    
    void divide()        
    {
        calcnum= num1*denom2;      
        calcden=denom1 * num2;      
    }
    void exit()      
    {
        cout<<"Have a nice day. ";      
    }
    
    void main()        
    {
         
    do while(choice!='5')
     {
        cout<<"Enter a number from the menu: ";    
        cin >> choice;
        menu();        
        cout<< "Enter the firts numerator: ";    
        cin >>num1;      
        cout<< "Enter the firts denomerator: ";  
        cin>>denom1;    
    cout<< "Enter the second numerator: ";
    cin>>num2;    
    cout<< "Enter the second numerator: ";    
    cin>>denom2;    
    cout<<calcnum<<" /"<<calcden;      
    }
    
    }
  • boxfish
    Recognized Expert Contributor
    • Mar 2008
    • 469

    #2
    It's not
    Code:
    do while (choice != '5')
    {
        // ...
    }
    It goes like
    Code:
    do
    {
        // ...
    } while (choice != '5');
    Hope this helps.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Possibly you mean 'while (choice != 5)' (skip that 'do') but there is a lot more wrong:

      1) menu() is not a function; menuFunction() is but you only call it after the user
      had to make a (blind) choice.
      2) you ask the user for a second numerator but you assign it to the first numerator.

      Fix those errors first, test it and see what happens.

      kind regards,

      Jos

      Comment

      Working...