Im just beginning to learn c++ and this is about the second day. Just wondering what you guys think and ways of improvement, efficiency and such.

Thanks guys!

/*
							Super Simple Calculator
									- Created By FTProtocol
*/

#include <iostream>
#include <math.h>
#include <stdio.h>
#include <windows.h>

#define nl '\n'

int x,y,choice;
int ans=0;
char loop;
float div1;

int main()
{
		printf(" Welcome to SCC - V2.0");
		Sleep(1500);
		printf("\n    - Created by FTProtocol");
		Sleep(5000);
		system("cls");
		printf(" Would you like to continue? (y/n): ");
		scanf("%s",&loop);

		if (loop =='y' || loop =='Y')
		{
			system("cls");
			printf("\n Please enter two numbers");
			printf("\n -----------------------");

			printf("\n\n Please enter the first number: ");
			scanf("%i",&x);

			printf("\n Please enter the second number: ");
			scanf("%i",&y);

			system("cls");

			printf("\n Select an operation.");
			printf("\n\n 1. Addition");
			printf("\n 2. Subtraction");
			printf("\n 3. Multiplication");
			printf("\n 4. Division");

			printf("\n\n Please make your choice: ");
			scanf("%i",&choice);
		
			switch(choice)
			{
			case 1 :
				printf(" Answer: %i %c %c",(ans=x+y),nl,nl);
				printf(" Answer: %i %c %c",(ans=x+y),nl,nl);
				printf(" Answer: %i %c %c",(ans=x+y),nl,nl);
			case 2 :
				printf(" Answer: %i %c %c",(ans=x-y),nl,nl);
			case 3 :
				printf(" Answer: %i %c %c",(ans=x*y),nl,nl);
			case 4 :
				printf(" Answer: %i %c %c",(div1=x/y),nl,nl);
			default :
				printf("\n Illegal operation selected");
			}
				Sleep(1000);
				printf(" Thanks for using SSC - Program will now restart!%c%c",nl,nl);
				Sleep(3000);
				system("cls");
		}
		else{
				printf("\n Good-Bye :O %c%c",nl,nl);
				system("PAUSE");
		return 0;}

	main();
	return 0;
}

Im just beginning to learn c++ and this is about the second day. Just wondering what you guys think and ways of improvement, efficiency and such.

Thanks guys!

/*
							Super Simple Calculator
									- Created By FTProtocol
*/

#include <iostream>
#include <math.h>
#include <stdio.h>
#include <windows.h>

#define nl '\n'

int x,y,choice;
int ans=0;
char loop;
float div1;

int main()
{
		printf(" Welcome to SCC - V2.0");
		Sleep(1500);
		printf("\n    - Created by FTProtocol");
		Sleep(5000);
		system("cls");
		printf(" Would you like to continue? (y/n): ");
		scanf("%s",&loop);

		if (loop =='y' || loop =='Y')
		{
			system("cls");
			printf("\n Please enter two numbers");
			printf("\n -----------------------");

			printf("\n\n Please enter the first number: ");
			scanf("%i",&x);

			printf("\n Please enter the second number: ");
			scanf("%i",&y);

			system("cls");

			printf("\n Select an operation.");
			printf("\n\n 1. Addition");
			printf("\n 2. Subtraction");
			printf("\n 3. Multiplication");
			printf("\n 4. Division");

			printf("\n\n Please make your choice: ");
			scanf("%i",&choice);
		
			switch(choice)
			{
			case 1 :
				printf(" Answer: %i %c %c",(ans=x+y),nl,nl);
				printf(" Answer: %i %c %c",(ans=x+y),nl,nl);
				printf(" Answer: %i %c %c",(ans=x+y),nl,nl);
			case 2 :
				printf(" Answer: %i %c %c",(ans=x-y),nl,nl);
			case 3 :
				printf(" Answer: %i %c %c",(ans=x*y),nl,nl);
			case 4 :
				printf(" Answer: %i %c %c",(div1=x/y),nl,nl);
			default :
				printf("\n Illegal operation selected");
			}
				Sleep(1000);
				printf(" Thanks for using SSC - Program will now restart!%c%c",nl,nl);
				Sleep(3000);
				system("cls");
		}
		else{
				printf("\n Good-Bye :O %c%c",nl,nl);
				system("PAUSE");
		return 0;}

	main();
	return 0;
}

I'd get rid of the pauses. system("PAUSE") is frowned upon by many people. There are some good threads explaining why and how to avoid it on Daniweb. You should add some "break" commands to your case statement. Right now it is implementing all cases when you pick addition.

well i did use break; originally but then a friend of mine said they weren't needed but i never tested it so thats my fault.

Ill try have a look around for system("pause");

>a friend of mine said they weren't needed
In that case, I wouldn't recommend relying on your friend for teaching you good coding practices. A break statement is always needed in a switch() statement unless you want execution to continue into the next case, or you're already at the last case.

>Ill try have a look around for system("pause");
I'd recommend this one, written by one of our moderators here:

http://www.gidnetwork.com/b-61.html

This article has been dead for over six months. Start a new discussion instead.