• Log in or sign up for an account here: https://www.sythe.org/login

After 2 days of C++

Status
Not open for further replies.

`Sp3ke

Member
Joined
Aug 2, 2007
Sythe Gold
0
Messages
80
Well my first project after 2 days of C++, any c&c appreciated.

Oh and I know using system() is bad programming.

Code:
/*
========================
-----Calculator V1------
========================
- Created in Visual C++ - 
========================
*/

#include "stdafx.h"
#include <iostream>
using namespace std;

//Multiplication declarations, definitions later in the program
void Adding(int FirstNumber, int SecondNumber);
void Subtracting(int FirstNumber, int SecondNumber);
void Division(int FirstNumber, int SecondNumber);
void Multiplication(int FirstNumber, int SecondNumber);

int main()
{
	int FirstNumber, SecondNumber;
	SecondNumber = FirstNumber = 0; //Must be valued to something
	int ChoiceMenu;
	char PlayAgain;
	do{ //Start of do-loop
		system("CLS"); //Once the loop runs again the previous text will be cleared
		cout<<"====================="<<endl;
		cout<<"--- Calculator V1 ---"<<endl;
		cout<<"====================="<<endl;
		//Startup-Menu
		cout<<"Menu (1-5)"<<endl;
		cout<<"1) Adding"<<endl;
		cout<<"2) Subtracting"<<endl;
		cout<<"3) Division"<<endl;
		cout<<"4) Multiplication"<<endl;
		cout<<"5) Quit"<<endl;
		cin>>ChoiceMenu; 

		switch(ChoiceMenu)
		{
		case 1:
			Adding(FirstNumber,SecondNumber);
			break;
		case 2:
			Subtracting(FirstNumber,SecondNumber);
			break;
		case 3:
			Division(FirstNumber,SecondNumber);
			break;
		case 4:
			Multiplication(FirstNumber,SecondNumber);
			break;
		case 5:
			return 0;
		}
		cout<<"Do you wish to use again (Y/N)?\n";
		cin>>PlayAgain;
	}while(PlayAgain == 'y' || PlayAgain == 'Y'); //If user inputs "Y" or "y" then loop continues, else it breaks

} //End of do-loop

void Adding(int FirstNumber, int SecondNumber)
{
		system("CLS");
	cout<<"--------------------"<<endl;
	cout<<"----- ADDITION -----"<<endl;
	cout<<"--------------------"<<endl<<endl;
	cout<<"Enter your first number\n";
	cin>>FirstNumber;
	cout<<"Enter your second number\n";
	cin>>SecondNumber;
	cout<<endl;
	cout<<"Calculating........."<<endl<<endl;
	cout<<"-------------------------------------------------------------------"<<endl;
	cout<<FirstNumber<< " + "<< SecondNumber<< " = "<< FirstNumber+SecondNumber<<endl;
	cout<<"-------------------------------------------------------------------"<<endl<<endl<<endl;
}
void Subtracting(int FirstNumber, int SecondNumber)
{
		system("CLS");
	cout<<"--------------------"<<endl;
	cout<<"----- SUBTRACTION -----"<<endl;
	cout<<"--------------------"<<endl<<endl;
	cout<<"Enter your first number\n";
	cin>>FirstNumber;
	cout<<"Enter your second number\n";
	cin>>SecondNumber;
	cout<<endl;
	cout<<"Calculating........."<<endl<<endl;
	cout<<"-------------------------------------------------------------------"<<endl;
	cout<<FirstNumber<< " - "<< SecondNumber<< " = "<< FirstNumber-SecondNumber<<endl;
	cout<<"-------------------------------------------------------------------"<<endl<<endl<<endl;
}
void Division(int FirstNumber, int SecondNumber)
{
		system("CLS");
	cout<<"--------------------"<<endl;
	cout<<"----- DIVISION -----"<<endl;
	cout<<"--------------------"<<endl<<endl;
	cout<<"Enter your first number\n";
	cin>>FirstNumber;
	cout<<"Enter your second number\n";
	cin>>SecondNumber;
	cout<<endl;
	cout<<"Calculating........."<<endl<<endl;
	cout<<"-------------------------------------------------------------------"<<endl;
	cout<<FirstNumber<< " / "<< SecondNumber<< " = "<< FirstNumber/SecondNumber<<endl;
	cout<<"-------------------------------------------------------------------"<<endl<<endl<<endl;
}
void Multiplication(int FirstNumber, int SecondNumber)
{
		system("CLS");
	cout<<"--------------------------"<<endl;
	cout<<"----- MULTIPLICATION -----"<<endl;
	cout<<"--------------------------"<<endl<<endl;
	cout<<"Enter your first number\n";
	cin>>FirstNumber;
	cout<<"Enter your second number\n";
	cin>>SecondNumber;
	cout<<endl;
	cout<<"Calculating........."<<endl<<endl;
	cout<<"-------------------------------------------------------------------"<<endl;
	cout<<FirstNumber<< " * "<< SecondNumber<< " = "<< FirstNumber*SecondNumber<<endl;
	cout<<"-------------------------------------------------------------------"<<endl<<endl<<endl;
}
 
Yeah...C++ is to confusing for me. I'll stick with my c# Lol.
 
to be brutally honest this thread only attracts retards because the OP is itself retarded.
regardless, have you never heard of function pointers and arrays?
 
nice job = ) , i took Intro to C++ then i learned JaVa and now i mostly use java but C++ is fun too.
 
to be brutally honest this thread only attracts retards because the OP is itself retarded.
regardless, have you never heard of function pointers and arrays?


he said its been 2 days -.- You wouldn't learn that in the first 2 days of C++ programming. Nice job in programming though.
 
Decent work for 2 days...when I first started I focused on actual computing rather than time-consuming decorations with cout...lol. Oh, and you don't need all those cout's, as one cout for each block of text will suffice.

Anyways, I think you're trying to do too much too fast. You probably want to focus on if's then while's/do-while's then for's. Making that calculator makes use of a switch (which is an if-else) and a do-while, but I don't think you quite understand them yet. Some great ways that I learned about for's and if's was by sorting numbers (either a set number or any amount), testing for prime numbers, or printing out tables (try a multiplication table).

Nice job, but I think you're trying to go too fast...you should probably do some problems with if's before you even get to loops...
 
Status
Not open for further replies.
Runescape Gamblingrunescape gambling
Back
Top