I am still a beginner, I recently started learning C++. However I am writing a program that converts currencies. For example Dollars to Euros. However when I have them pick the number of the currency they want to convert the number 2 doesnt work. Here it is:

#include <iostream>
using namespace std;

int main()
{
	int currency;
	float eurosdollars;
	float dollarseuros;
	
	cout<<"1.Dollars to Euros\n"<<endl;
	cout<<"2.Euros to Dollars\n"<<endl;
	
	cout<<"Please enter the number of the currency you want to convert: ";
	cin>>currency;
	
	if (currency==1)
	cout<<"Please enter the Dollars you would like to convert to Euros: ";
	cin>>eurosdollars;
	
	cout<<"You have entered "<<eurosdollars<<" dollars which is equal to "<<eurosdollars * 0.678518116<<" euros."<<endl;
	
	if (currency==2)
	cout<<"Please enter the Euros you would like convert to Dollars: ";
	cin>>dollarseuros;
	
	cout<<"You have entered "<<dollarseuros<<" Euros which is equal to "<<dollarseuros * 1.4738 <<" Dollars."<<endl;
	}

Right at the if (currency==2)
cout<<"Please enter the Euros you would like convert to Dollars: ";
cin>>dollarseuros; it never works when you type in 2 it doesn't go to that. It just stays the same even if you keep typing in 2.

I think you need to put braces around your if statements. Otherwise its always going to read in the eurosdollars variable. Its a good practice put braces around the body of the condition, even if its one line.

if (currency==1){
	cout<<"Please enter the Dollars you would like to convert to Euros: ";
	cin>>eurosdollars;
	
	cout<<"You have entered "<<eurosdollars<<" dollars which is equal to "<<eurosdollars * 0.678518116<<" euros."<<endl;
}

Using proper formatting helps solve problems like this...

Thank you I figured it out, I need blocks around my input.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.