plzzz!!! answer this c++proggram on how to use do,while code?
this is my code so far!!!,,
where do i put do and while??
#include<iostream>
#include<string>
using namespace std;
void main()
{
string password;
float sum,difference,product,qoutient,num1,num2;
char mychoice;
cout<<"enter your password"<<endl;
cin>>password;
if(password=="frozen")
{
cout<<"select your choice:"<<endl;
cout<<"select a for addition:"<<endl;
cout<<"select s for subtraction:"<<endl;
cout<<"select m for multiplication:"<<endl;
cout<<"select d for division:"<<endl;
cin>>mychoice;
cout<<"enter do you want to continue"<<endl;
switch(mychoice)
{
case'a':
cout<<"enter first number:"<<endl;
cin>>num1;
cout<<"enter second number:"<<endl;
cin>>num2;
sum=num1+num2;
cout<<"the sum is:"<<sum<<endl;
break;
case's':
cout<<"enter first number:"<<endl;
cin>>num1;
cout<<"enter second number:"<<endl;
cin>>num2;
difference=num1-num2;
cout<<"the diffrence is:"<<difference<<endl;
break;
case'm':
cout<<"enter first number:"<<endl;
cin>>num1;
cout<<"enter second number:"<<endl;
cin>>num2;
product=num1*num2;
cout<<"the product is:"<<product<<endl;
break;
case'd':
cout<<"enter first number:"<<endl;
cin>>num1;
cout<<"enter second number:"<<endl;
cin>>num2;
qoutient=num1/num2;
cout<<"the qoutient is:"<<qoutient<<endl;
break;
default:
cout<<"invalid choice"<<endl;
}
}
else
cout<<"access denied"<<endl;
}
This is how I would of did it
Code:
#include <iostream>
#include <string>
using namespace std;
double addition ( double x, double y );
double subtraction ( double x, double y );
double multiplication ( double x, double y );
double division ( double x, double y );
int main ( )
{
string thePassWord = "frozon";
string changePassWord = "fire";
string passWord;
char myChoice;
double x, y;
int count = 0;
do {
cout << "Enter password: \n>";
getline ( cin, passWord, '\n' );
count++;
if ( count == 3 )
{
cout << "Error: You enter the password wrong 3 time. \n";
cout << "Password is being changes. \n";
thePassWord.swap (changePassWord);
}
} while ( passWord != thePassWord );
if ( passWord == thePassWord )
{
while ( true )
{
cout << "Select your choice: \n";
cout << "Select \'a\' for addition: \n";
cout << "Select \'s\' for subtraction: \n";
cout << "Select \'m\' for multiplication: \n";
cout << "Select \'d\' for division: \n>";
cin >> myChoice;
switch ( myChoice )
{
case 'a':
case 'A':
cout << "Addition: \n";
cout << "First number: \n>";
cin >> x;
cout << "Second number: \n>";
cin >> y;
cout << endl;
cout << x << " + " << y << " = " << addition ( x, y ) << "\n\n";
cin.get();
break;
case 's':
case 'S':
cout << "Subraction: \n";
cout << "Frist number: \n>";
cin >> x;
cout << "Second number: \n>";
cin >> y;
cout << endl;
cout << x << " - " << y << " = " << subtraction ( x, y ) << "\n\n";
cin.get();
break;
case 'm':
case 'M':
cout << "multiplication: \n";
cout << "First number: \n>";
cin >> x;
cout << "Second number: \n";
cin >> y;
cout << endl;
cout << x << " * " << y << " = " << multiplication ( x, y ) << "\n\n";
cin.get();
break;
case 'd':
case 'D':
cout << "division: \n";
cout << "First number: \n>";
cin >> x;
cout << "Second number: \n>";
cin >> y;
cout << endl;
if ( y == 0 )
{
cout << "Error: \n\n";
continue;
}
cout << x << " / " << y << " = " << division ( x, y ) << "\n\n";
cin.get();
break;
default:
cout << endl;
cout << "Error: Invalid Choice. \n\n";
cin.get();
break;
}
}
}
cin.get();
return ( 0 );
}
double addition ( double x, double y )
{
return x + y;
}
double subtraction ( double x, double y )
{
return x - y;
}
double multiplication ( double x, double y )
{
return x * y;
}
double division ( double x, double y )
{
return x / y;
}
Just an idea........