Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


balachandra.m.v
c++
1 Answer(s)      4 years and 2 months ago
Posted in : Java Beginners


1. Create the equivalent of a four-function calculator. The program should request the user to
enter a number, an operator, and another number. (Use floating point.) It should then carry out the
specified arithmetical operation: adding, subtracting, multiplying, or dividing the two numbers. Use
a switch statement to select the operation. Finally, display the result.
When it finishes the calculation, the program should ask if the user wants to do another calculation.
The response can be 'y' or 'n'. Some sample interaction with the program might look like this:
Enter first number, operator, second number: 10 / 3
Answer = 3.333333
Do another (y/n)? y
Enter first number, operator, second number: 12 + 100
Answer = 112
Do another (y/n)? n

Advertisement
View Answers

August 7, 2010 at 3:49 PM


Hi Friend,

Try the following code:

#include <iostream.h>
#include <conio.h>

void main(){
float num1,num2,total;
char ch,ch1;
clrscr();
do{
cout<<"Enter first number, operator, second number: ";
cin<<"%f %c %f", &num1, &ch, &num2 );
cin >>num1>>ch>>num2;

switch( ch ) {
case '+':
total = num1 + num2;
cout<<total<<endl;
break;
case '-':
total = num1 - num2;
cout<<total<<endl;
break;
case '*':
total = num1 * num2;
cout<<total<<endl;
break;
case '/':
total = num1 / num2;
cout<<total<<endl;
break;
default:
cout<<"Invalid option";
}
cout<<"\n";
cout<<"Do another?y/n:";
cin>>ch1;
}
while(getchar()!='n');
getch();
}

Thanks


Related Tutorials/Questions & Answers:
c#
c#  how to find out the size of the BMP image in C
C++
C++  How can i write this in dev c
Advertisements
C++
C++  How can i write this in dev c
c++
c++  use a prgrm as an example to xplain-: a)class b)object c)message d)cope resolution operator
c#
c#  how to find out the size of the BMP image
c++
c++  write a programme that calculates the area and circumference of a rectangle
C++
C++  dear sir How to create windows form application for login screen using C++? USER Name -TESTADMIN Password -testuser
c++
c++  i use turbo c++...i want to change the background color...what is the command for it and the header file used
c++
c++  i use turbo c++...i want to change the background color...what is the command for it and the header file used
c++
c++  i use turbo c++...i want to change the background color...what is the command for it and the header file used
c++
c++  differenciate btw.-a)local & public variables b)pre-defined & user defined functions c)fnctn prototype,defination & fnctn code.use code examples
C++
C++  differenciate btw.-a)local & public variables b)pre-defined & user defined functions c)fnctn prototype,defination & fnctn code.use code examples
c++
c++  differenciate btw.-a)local & public variables b)pre-defined & user defined functions c)fnctn prototype,defination & fnctn code.use code examples
C++
C++  Trace the bubble sort using the following integers,which represent the elements in an array. 5,7,3,8,6,7,3
c++
c++  write a prgrm tht accepts 3 integer values,then with a function to swap the values
C++
C++  Describe the principle advantages of deploying a linked list versus a static array when implementing a Queue or a Stack
C#
C#  i need a code that will make program perform the basic operations upon the data Listview save, update and cancel
C++
C++  I have been asked to write a programme that gets five values,gets the sum,average and product please help me
C#
C# register form  i want to generate a user id automatically after filling their register form and i want to show their id to their email? please reply me soon
c++
c++  Consider the following function: int funcExercise7(int list[], int size) { int sum = 0; for (int index = 0; index < size; index++) sum = sum + list[index]; return sum
c++
c++  Consider the following declarations: class xClass { public: void... private members does class xClass have? c. How many constructors does class xClass.... Write a C++ statement that prints the values of the data members of the object
c++
c++  .write a program that accepts 5 subjects of a student,it should have a function to calculate the average & another function to grade.grade should be as follows-<40=E,40-49=D,50-59=C,60-69=B & >70
c++
c++  write a prgrm tht calculates the surface area of a cylinder.the prgrm shld find the circumfrance and have a function that calculates the fadius and another to calculate the surface area
C++
C++  write a prgrm tht gets five values,gets the sum,average &...; #include <conio.h> void main() { clrscr(); int a,b,c,d,e,sum; float average...;>b>>c>>d>>e; sum=a+b+c+d+e; average=sum/5; product=a*b*c*d
c++
c++  write a program that gets a key or character from the keyboard and displays it ASII code in decimal, hexadecimal and binary form.It must also give a description of the key pressed
c++
c++  Consider the following declarations: class xClass { public: void func(); void print() const; xClass (); xClass (int, double); private: int u... private members does class xClass have? c. How many constructors does class xClass
c++
c++  Write a console based C++ program that reads student information from a text file, build an array of objects of type class StudentInfo... name with the minimum GPA 7) Display Student GPAs as Letter Grades (A, B, C, D
c++
c++  Characterize the following algorithm in terms of Big-O notation. Also find the exact number of additions executed by the loop. (Assume that all variables are properly declared.) for (int i = 1; i <= n; i++) sum = sum + i
c++
c++  Characterize the following algorithm in terms of Big-O notation. for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) for (int k = 1; k <= n; k++) cout << i + j + k
C++
C++  . Consider the definition of the following class: class CC { public: CC(); //Line 1 CC(int); //Line 2 CC(int, int); //Line 3 CC(double, int); //Line 4 . . . private: int u; double v
c++
c++  .write a prgrm tht accepts 5 subjects of a student,it shld hv a function to calculate the average & another function to grade.grade shld be as follows-<40=E,40-49=D,50-59=C,60-69=B & >70
 

 

 

DMCA.com