Tiny bit more advanced calculator (Addition Only atm)

Posts 1–9 of 9 · Page 1 of 1
Tiny bit more advanced calculator (Addition Only atm)
This should, in theory, allow you to add any amount of numbers together, until, of course, you reach the max value that a unsigned long integer can hold, because then, it will freeze there.

I wrote this from scratch at school, so don't even try to claim that any of this code is yours.

You can do whatever you want with the source, it doesn't matter to me.

Code:
/////////////////////////////////////////
////	Eddie's Ownage Calculator    ////
/////////////////////////////////////////

#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
void test()
{
	cout << "How many numbers?" << endl;
    int num;
    unsigned long int answer = 0;
    int nums;
    cin >> nums;
    cout << endl << "What operation would you like to use?" << endl;
    char choice;
    cin >> choice; 
    switch (choice)
    {
	case '+':
		for(int i = 0; i <= nums; i++)
		{
			if(i == 1)
			{
				cout << "First Number? \n";
				cin >> num;
				answer = num + answer;
			} else if(i >= 2) {
				cout << "Next Number? \n";
				cin >> num;
				answer = num + answer;
			}
		}
		break;
	case '-':
		break;
	case '*':
		break;
	case '/':
		break;
	}
	cout << "The answer is: " << answer << endl;
}
int main()
{
	test();
	system("pause");
	return 0;
}
If you have any suggestions, tell me. I'll be adding other operations later, since they won't take to long.
No offense, but why would someone even want to steal this.
Quote Originally Posted by zhaoyun333 View Post
No offense, but why would someone even want to steal this.
Because they are so noobish they don't even know what it is
I think you can even make your value range longer with "unsigned long long". Never tried it before. It can hold at least 64 bits so it might only work on a 64 bit OS.
The only reason I would hand program a calculator is if I was trying to calculate extremely precise or extroadinarily large values. That's when it gets interesting, because a double is essentially the largest value you can calculate on a 32 bit machine, so you have to find otherways around it to make calculate these numbers... so that they don't overflow.
Quote Originally Posted by why06 View Post
The only reason I would hand program a calculator is if I was trying to calculate extremely precise or extroadinarily large values. That's when it gets interesting, because a double is essentially the largest value you can calculate on a 32 bit machine, so you have to find otherways around it to make calculate these numbers... so that they don't overflow.
a calculator is very good practice for learning if/else statements, switch case.

but i see your point, making a calculator just because you want a project is pretty useless.
Quote Originally Posted by origami7795 View Post
a calculator is very good practice for learning if/else statements, switch case.

but i see your point, making a calculator just because you want a project is pretty useless.
Yeh it is good practice. Practicing the little things like this will help you to get a good grasps on the concepts. I tried something similar once... I tried to make a chemical formula calculator, but that was before I realized I didn't know shit about chemistry and dropped the course... =/
Quote Originally Posted by why06 View Post
Yeh it is good practice. Practicing the little things like this will help you to get a good grasps on the concepts. I tried something similar once... I tried to make a chemical formula calculator, but that was before I realized I didn't know shit about chemistry and dropped the course... =/
Wow...... And i'm guessing you wrote this in java?

My friend did the exact same thing. Like in java too =0 . . .

He did it really grossly though. Too much repeating code where loops could have been used, no structure (it was messy as hell), and other such peeves of mine.
4LL 0F TH1S C4LCULATORZ R B3L00NG 2 M3H!!1

Good job I guess
Posts 1–9 of 9 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

Need help?