3 Replies - 517 Views - Last Post: 10 February 2013 - 06:58 PM Rate Topic: -----

#1 rrmv951r  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 02-February 13

Help on exchange rate project

Posted 09 February 2013 - 03:08 PM

the purpose of this project is simple it prompts the user to input the current exchange rate between U.S dollars and Japanese yen then it prompts the user to enter the amount of dollars he or she wants to convert to yen. It does the calculations right but how do i get it to only ask for the exchange rate once...and also when i enter "0 and "enter"" i have to do it twice to calculate any advice on how to fix the problem?


#include<iostream>

using namespace std ;

int main ()

{
    double exchange_rate = 0 ;
    double dollar = 0 ;
    bool more = true ;
    
    while (more)
    {
       
        double input_er ;
        cout<< " Please enter U.S dollar to Japanese yen \n exchange rate \n Example 1 dollar is equal to ___ yen \n" ;
        cin>> input_er ;
        
        double input_dollar ;
        cout<< " Enter the ammount of dollars you wish to convert to yen \n" ;
        cout<< " Enter the value 0 to calculate \n" ;
        cin>> input_dollar ;
        
        if ( input_dollar == 0)
            more = false ;

        else
        {
            exchange_rate = input_er ;
            dollar = dollar + input_dollar ;
            
        }
    
    }
    
        if (dollar > 0)
             cout<< " You Have " << dollar * exchange_rate << " Yen \n" ;
        
        return 0 ;

        
}


Is This A Good Question/Topic? 0
  • +

Replies To: Help on exchange rate project

#2 Adak  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 331
  • View blog
  • Posts: 1,168
  • Joined: 01-April 11

Re: Help on exchange rate project

Posted 09 February 2013 - 07:55 PM

Unless the exchange rate is changing between loops (doubtful), I'd ask the dollar to yen exchange rate just once, before the while loop. Otherwise, you'll be prompted for it on every loop.

I would remove the "enter the value 0 to calculate", because it makes no sense. If the user has entered an exchange rate, and they have entered a dollar amount OF COURSE they want to get a calculation. ;)

Also, I would delete the "dollar" variable. You need ONE dollar variable, not two.

It's always a bit clumsy when the program goes into a loop, without confirming the user wants to do that calculation. How about a simple menu, and then the loop runs ONLY when the user enters that menu choice? Just an idea though.
Was This Post Helpful? 2
  • +
  • -

#3 rrmv951r  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 8
  • Joined: 02-February 13

Re: Help on exchange rate project

Posted 10 February 2013 - 05:42 PM

View PostAdak, on 09 February 2013 - 07:55 PM, said:

Unless the exchange rate is changing between loops (doubtful), I'd ask the dollar to yen exchange rate just once, before the while loop. Otherwise, you'll be prompted for it on every loop.

I would remove the "enter the value 0 to calculate", because it makes no sense. If the user has entered an exchange rate, and they have entered a dollar amount OF COURSE they want to get a calculation. ;)/>

Also, I would delete the "dollar" variable. You need ONE dollar variable, not two.

It's always a bit clumsy when the program goes into a loop, without confirming the user wants to do that calculation. How about a simple menu, and then the loop runs ONLY when the user enters that menu choice? Just an idea though.

thanks I took the part where it asks for the exchange rate out of the loop and it works a lot better. Unfortunately am you can see i am an amateur at c++ soo i do not know how to create a menu just yet. I'm sure my coding should get better soon, thanks for the help
Was This Post Helpful? 0
  • +
  • -

#4 Adak  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 331
  • View blog
  • Posts: 1,168
  • Joined: 01-April 11

Re: Help on exchange rate project

Posted 10 February 2013 - 06:58 PM

I don't have a C++ compiler to test it, so tell me, how goes your program?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1