473,507 Members | 3,678 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calculator Question

11 New Member
I made 1 calculator in C++ but it looks preatty simple. If some 1 sees it, he will tell that i made it in 2 mins... How can i change the design and looks of the C++ programs? I mean i want my calculator to look like this 1 but i don't know how to modify it to my needs. Should i try learning C# for that? I need some advise, btw im only a beginner...

Code:

Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<windows.h>
  3. #include<mmsystem.h>
  4.  
  5. using namespace std;
  6.  
  7. int main(void)
  8. {
  9.  double n1;
  10.  double n2;
  11.  char redo;
  12.  char operation;
  13.  do
  14.  {
  15.       system("CLS"); // If a person enters y it returns the program to this line.
  16.       system("TITLE Calculator"); // Title of Program
  17.       system("Color B4"); // Writing Color
  18.       cout << "Please enter your desired calculation: " << endl;
  19.       cin >> n1 >> operation >> n2;
  20.       switch(operation)
  21.       {
  22.       case '+':
  23.                  cout << "Your result is: " << n1 + n2 << endl;
  24.                  break;
  25.       case '-':
  26.                  cout << "Your result is: " << n1 - n2 << endl;
  27.                  break;  
  28.       case '*':
  29.                  cout << "Your result is: " << n1 * n2 << endl;
  30.                  break;
  31.       case 'x':
  32.                  cout << "Your result is: " << n1 * n2 << endl;
  33.                  break;
  34.       case 'X':
  35.                  cout << "Your result is: " << n1 * n2 << endl;
  36.                  break;
  37.       case '/':
  38.                  if(n2 == 0){
  39.                  cout << "That is an invalid operation" << endl;
  40.                  }else{   
  41.                  cout << "Your result is: " << n1 / n2 << endl;
  42.                  }
  43.                  break;
  44.       default:
  45.           cout << "That is an invalid operation" << endl;
  46.           break;               
  47.       }
  48.       cout << "Do you want to calculate something else?(Y/N)" << endl;
  49.       cin >> redo;
  50.  }while(redo == 'y' || redo == 'Y'); // || means or. If a person enters y or Y the program starts again and return to the system CLS line
  51.  system("PAUSE");
  52.  return 0;      
  53. }
Sep 24 '09 #1
8 2943
Markus
6,050 Recognized Expert Expert
Are you talking about creating a GUI (graphical user interface)? If so, you do not need to use C# - check out one of the many GUI libraries available for C/C++ - a quick google will help you out (I recommend GTK).

Here's a link to the C++ Library for GTK: http://www.gtkmm.org/
Sep 24 '09 #2
IgorZ
11 New Member
What do u mean? How can i use them. I told you im a begginer can u give me step by step explanation? I think it will take 2 minutes of your valuable time...
Sep 24 '09 #3
Markus
6,050 Recognized Expert Expert
@IgorZ
First of all, my time's not that valuable - were it, I wouldn't be on here.

Second of all, I mean: is the root of your question that you would like a graphical interface for your application? That is, do you want fancy pointy-clicky stuff for the user?

Thirdly, I'm not a C/C++ developer - so any advice I can give wouldn't be reliable other than that I _know_ GTK+ is a very good UI library. The link I provided you has resources for documentation, downloads, help, etc. You can find them by looking - I won't do that for you.

Mark.
Sep 24 '09 #4
Banfa
9,065 Recognized Expert Moderator Expert
When using a GUI you normally have some sort of editor to create the GUI. In fact the video you link to shows the GUI editor for Visual C# but the GUI editor for Visual C++ is much the same and in fact most GUI editors have similar features, an area to design your Window on, a box of tools you can place on your Window.

Once you have place tools on the Window then you add code to run when the tool is used, for instance when a button is clicked. Then you compile and link in the usual way and that is about it.

If you drill down into the link provided by Markus you will find the documentation which explains the basics of how to use GTK
Sep 24 '09 #5
IgorZ
11 New Member
@ Banfa: I use Dev C++ program for compiling
Sep 24 '09 #6
Banfa
9,065 Recognized Expert Moderator Expert
Hmmm, it's a bit out of date but doesn't Dev-C++ include a GUI interface editor?
Sep 24 '09 #7
whodgson
542 Contributor
If you are familiar with BASIC you could use MS Visual Basic to achieve your objective ( like THIS) quite simply. If you want to persevere with C++ I think as a beginner you are heading into difficult waters unless you only want to employ '+' and '-' .
The difficulty is that if you want to enter say - 6.0 - 2.7 / 21.3 +5%2 from the keyboard and send a result -4.1268 (I hope that is correct!) to the screen you will have to deal with arithmetical precedence and probably parethisis. Bjarne Stroustrup devotes a couple of chapters (6 & 7) to this subject in his book Programming Principles and Practice Using C++.
hth`s
Sep 26 '09 #8
donbock
2,426 Recognized Expert Top Contributor
@whodgson
The classic way to handle precedence and parentheses is to construct an operator/operand stack and load it with the Reverse-Polish equivalent of the input infix expression.

If you're not already familiar with the terms infix and postfix then a full-blown calculator may be a bit too big a project for a beginner.
Sep 28 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

6
7291
by: Rafael | last post by:
Hi Everyone, I need some help with my calculator program. I need my program to do 2 arguments and a 3rd, but the 3rd with different operators. Any help would be great. Here is my code.... ...
3
5193
by: Paul | last post by:
I want to make a simple calculator program but dont know where to get started. This is not GUI but a simple terminal program. It would get input like this Enter number: 5 + 10
3
2067
by: Art | last post by:
Hi, In part of my application the user may need to do a simple arithmetic calculation in order to get the value to put in a text box. I was thinking that it would be good if I could display the...
24
6285
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to...
19
3987
by: TexasNewbie | last post by:
This was originally just a calculator without a decimal point. After I added the decimal, it now tells me invalid second number. //GUI Calculator Program import javax.swing.*; import...
0
1581
by: wocosc | last post by:
Alright.. I have the basic interface of the Body Mass Index worked out. However, I dont know how to get the feet,inches, and weight to be be multiplied: (w / (h * 12 + x) * (h * 12 + x)) * 703) ...
3
11831
by: itsmichelle | last post by:
This is a very primative code of a java swing calculator. I have assigned all the number buttons and the operator buttons and I can add, subtract, multiply, and divide two numbers together. However,...
4
2261
by: bravephantom | last post by:
hi first how can i design the interface of a calculator similar to that of windows? i'll add some functions later to work as scientific calculator. the question now is how to implement the panel....
3
2878
by: mandy335 | last post by:
public class Calculator { private long input = 0; // current input private long result = 0; // last input/result private String lastOperator = ""; // keeps track of...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7110
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7314
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7030
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5041
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.