Need help looping my switch.

Hi, I've been trying to make a program where you have to log in with username and password, to be able to use a calculator, made with a switch function. What I have been trying to do, is looping the calculator, so that it returns after getting an answer (return so that you can start a new calculation)

here is my code:

#include <iostream>
#include <string>

using namespace std;

int main () {

string username;
string password;
double num1;
double num2;
char charac;
double result;

cout << "Enter your username: ";
getline(cin, username, '\n');

cout << "Enter your password: ";
getline(cin, password, '\n');

if (username == "thor" && password == "123"){
cout<< "Access Accepted." << endl;

cout << "Enter your first number here: " << endl;
cin >> num1;

cout << "Enter character: " << endl;
cin >> charac;

cout << "Enter second number: " << endl;
cin >> num2;

switch (charac){


case '+':
result = num1 + num2;
cout << result << endl;
break;

case '-':
result = num1 - num2;
cout << result << endl;
break;

case '/':
result = num1 / num2;
cout << result << endl;
break;

case '*':
result = num1 / num2;
cout << result << endl;
break;

}
}

else{
cout << "Access denied." << endl;
return 0;
}
return 0;
}

Thank you!
1
2
3
4
5
6
7
8
9
10
11
char exit = 'a'; 
while(true)//Infinite loop
{
    //Calculator here
    std::cout << "Do you wish to exit?\n";    
    std::cin >> exit; 
    if(exit == 'y') //If the user wants to exit. 
    {
         break;//We break out of the loop.
    }
}
Thank you sir!
Topic archived. No new replies allowed.