I have a s,all query regarding c++ language. I want to create a program in order to run as a calculator in application. I am actually getting confused as not a better programmer in c++
Please provide some assistance
I have a s,all query regarding c++ language. I want to create a program in order to run as a calculator in application. I am actually getting confused as not a better programmer in c++
Please provide some assistance
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
void instructUser();
double doDivideZero(double &);
int main()
{
instructUser();
double displayedVal;
double newEntry;
char command_character ;
displayedVal = 0.0;
cout << " Enter accepted Operator:" ;
cin >> command_character;
while (command_character != 'Q' || command_character != 'q')
{
switch(command_character)
{
case 'c':
case 'C': displayedVal = 0.0;
break;
case '+': cout << " Enter Number:";
cin >> newEntry;
displayedVal = displayedVal + newEntry;
break;
case '-': cout << " Enter Number:";
cin >> newEntry;
displayedVal = displayedVal - newEntry;
break;
case '*': cout << " Enter Number:";
cin >> newEntry;
displayedVal = displayedVal * newEntry;
break;
case '/': cout << " Enter Number:";
cin >> newEntry;
displayedVal = displayedVal / newEntry;
if (newEntry == 0)
{
doDivideZero(double &);
}
break;
case '^': cout << " Enter Number:";
cin >> newEntry;
displayedVal = pow (displayedVal,newEntry);
break;
default : cout << " Unacceptable Operator(" << command_character << ")" << endl;
}
cout << " The result so far is: " <<displayedVal<< endl;
cout << " Enter Operator:";
cin >> command_character;
}
system ("pause");
return 0;
}
void instructUser()
{
cout << " " <<endl;
cout << "
#include <iostream.h>
#include <conio.h>
int mc(int x, int y) //Multiply two numbers
{
cout <<"\n\n"<< x <<" times "<< y <<" equals ";
return (x*y);
}
int ac(int a, int b) //Add two numbers
{
cout <<"\n\n"<< a <<" plus "<< b <<" equals ";
return (a+b);
}
int sc(int z, int c) //Subtract two numbers
{
cout <<"\n\n"<< z <<" minus "<< c <<" equals ";
return (z-c);
}
int dc(int o, int t) //Divide two numbers
{
cout <<"\n\n"<< o <<" divided by "<< t <<" equals ";
return (o/t);
}
void calc(char choice)
{
int on,tw,thr;
if (choice == '+') //This whole block checks what the user wants to calculate, and refers to the proper routine to calculate it.
{
cout<<"You selected "<<choice<<". Please enter two numbers,\nsepperated by spaces,";
cout<<"that you want to add."<<endl;//print instructions for the user
cin>>on;//Get the value of variable on
cin>>tw;//Get the value of variable tw
thr=ac(on,tw);//Get the sum of on and tw, and assign that value to thr
cout<<thr<<"\n\n\n\aThanks for using my calculator!";//Print a thank you message
}
else if (choice =='-')
{
cout<<"You selected "<<choice<<". Please enter two numbers,\nsepperated by spaces, that you want to subtract."<<endl;
cin>>on;
cin>>tw;
thr=sc(on,tw);
cout<<thr<<"\n\n\n\aThanks for using my calculator!";
}
else if (choice =='*')
{
cout<<"You selected "<<choice<<". Please enter two numbers,\nsepperated by spaces, that you want to multiply."<<endl;
cin>>on;
cin>>tw;
thr=mc(on,tw);
cout<<thr<<"\n\n\n\aThanks for using my calculator!";
}
else if (choice =='/')
{
cout<<"You selected "<<choice<<". Please enter two numbers,\nsepperated by spaces, that you want to divide."<<endl;
cin>>on;
cin>>tw;
thr=dc(on,tw);
cout<<thr<<"\n\n\n\aThanks for using my calculator";
}
else
{
cout<<"\nPlease reenter that value.\n\a";
cin>>choice;
calc(choice,);
}
}
void main()
{
clrscr();
int one, two, three;
char choice;
while (choice != 'e')
{
cout<<"\nPlease enter +,-,*, or / and then two numbers,\nsepperated by spaces, that you wish to\nadd,subtract,multiply,or divide.\nType e and press enter to exit.";
cin>>choice;
if (choice != 'e')
{
calc(choice);
}
}
}
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
cout<<" Quadratic Equation Calculator"<<endl<<"By Nerd"<<endl<<endl;
double a,b,c,d,x,y; //double or float should not matter
cout << "ax^2+bx+c=0" << endl;
cout << "Enter a Value for a: ";
cin >> a;
cout << endl;
cout << "Enter a value for b: ";
cin >> b;
cout << endl;
cout << "Enter a value for c: ";
cin >> c;
cout << endl;
d =((b*b)-(4*a*c));
if (d > 0)
{
cout << "There are 2 roots" << endl;
x =(-b + sqrt(d))/(2*a);
y =(-b - sqrt(d))/(2*a);
cout <<endl <<"Root 1: "<<x;
cout <<endl <<"Root 2: "<<y <<"\n";
}
else if (d == 0)
{
cout << "There is 1 root" << endl;
x = (-b)/(2*a);
cout <<"Root: "<<x << "\n";
}
else if (d < 0)
{
cout << "There are no real roots" << endl;
}
system( "PAUSE");
return 0;
}
Bookmarks