0

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;
    }   
}
3
Contributors
2
Replies
21
Views
3 Weeks
Discussion Span
Last Post by tinstaafl
0

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.

Edited by Tarek_2: typo

1

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.

Edited by tinstaafl

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.