convert from: loops properly
convert to: loops back to from (should just loop back to convert to:)

need some guidance

#include<iostream>
using namespace std;
int main()
{
    int num;
    char ch='y';
    int amount;
    int choice1,choice2;
    while(ch=='y'||ch=='Y')
    {
        do
        {
            system("cls");
            cout<<"\t\t|DLSL CURRENCY EXCHANGE PROJECT  |"<<endl;

            cout<<"convert currency from: ";
            cin>>choice1;
                if(choice1<=15) 
                {
                        cout<<"convert currency to: ";
                        cin>>choice2;
                        if(choice2<=15)
                        {
                                if(choice1==choice2)
                                {
                                    cout<<"invalid choice"<<endl;
                                    break;
                                }
                                else
                                {
                                cout<<"Enter amount to be converted: ";
                                cin>>amount;
                                cout << amount;
                                break;
                                }
                        }
                    }

        }
        while(choice2=true);
        cout<<"\nGo to Main Menu Press Y and N for Exit\n";
        cin>>ch;
    }   
}

Recommended Answers

All 2 Replies

First, choice2 is supposed to be an integer (int) but in the while condition, we can read (choice2=true)
Second, choice2=true is not a comparaison, it is always true. I think you should use choice2==true and here again choice2 is supposed to be compared to an int value not a boolean value.

Your main problem appears to be, you're using one loop, but expect it to return to 2 different places. Using one loop just for the first choice and a second loop for the second choice, will fix the immediate problem.

However, you should probably think about refactoring, and use a function to handle validating the inputs. Always remember that main should be just a jumping off point, not the whole program.

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.