Hello, this is Metalcrunch. I've been learning C++ over the past days and I thought I'd make a calculator. So I looked over the existing code on the internet on how to make a calculator, understood it, then made my own from the very scratch.
However, I'm having a few problems with it - Hope you guys can help me out! :D
main_calculator.cpp
//Calculator Script by Sass.
//main_calculator.cpp
//Default include's.
#include <iostream>
#include <windows.h>
using namespace std;
//Custom header file.
#include "header_calculator.h"
//Main()
int main()
{
//One-time welcome greeting:
SetConsoleTitle("Calculator v1.1");
cout << "Kalkulaator v1.1 by MetalCrunch." << endl;
cout << "---------------------------------------" << endl << endl;
//Main program:
for (;;) {
do {
cout << "1 - Addition." << endl;
cout << "2 - Subtraction." << endl;
cout << "3 - Multiplication." << endl;
cout << "4 - Division." << endl;
cout << "5 - Abimees." << endl;
cin >> choice; }
switch (choice) {
//Addition.
case 1:
cout << "Enter the first number: ";
cin >> num1;
cout << "\nEnter the second number: ";
cin >> num2;
result = num1 + num2;
cout << "Answer: ";
cout << result;
break;
//Subtraction.
case 2:
cout << "Enter the first number: ";
cin >> num1;
cout << "\nEnter the second number: ";
cin >> num2;
result = num1 - num2;
cout << "\nAnswer: ";
cout << result;
break;
//Multiplication.
case 3:
cout << "Enter the first number: ";
cin >> num1;
cout << "\nEnter the second number: ";
cin >> num2;
result = num1 * num2;
cout << "\nAnswer: ";
cout << result;
break;
//Division.
case 4:
cout << "Enter the first number: ";
cin >> num1;
cout << "\n Enter the second number: ";
cin >> num2;
result = num1 / num2;
cout << "\nAnswer: ";
cout << result;
break;
//"Information".
case 5:
cout << "Calculator v1.1 by Metalcrunch" << endl;
cout << "Enter the number 1-5, then answer the questions..." << endl;
cout << "The program will solve it all." << endl;
cout << "But please don't enter a value over 9 numbers, the program will crash!" << endl;
break;
default:
cout << "test";
break; }
}
return 0;
}
header_calculator.h
//Calculator Script
//header_calculator.h
#ifndef HEADER_CALCULATOR_H
#define HEADER_CALCULATOR_H
//Main int's, for calculation.
int num1, num2;
int result;
//The "choice" int.
int choice;
#endif
The build log.
Compiling...
main_calculator.cpp
c:\documents and settings\*********\my documents\visual studio 2008\projects\project1\calculator\calculator\main_calculator.cpp(31) : error C2059: syntax error : 'switch'
c:\documents and settings\*********\my documents\visual studio 2008\projects\project1\calculator\calculator\main_calculator.cpp(31) : error C2143: syntax error : missing ';' before '{'
c:\documents and settings\*********\my documents\visual studio 2008\projects\project1\calculator\calculator\main_calculator.cpp(33) : error C2046: illegal case
c:\documents and settings\*********\my documents\visual studio 2008\projects\project1\calculator\calculator\main_calculator.cpp(44) : error C2046: illegal case
c:\documents and settings\*********\my documents\visual studio 2008\projects\project1\calculator\calculator\main_calculator.cpp(55) : error C2046: illegal case
c:\documents and settings\*********\my documents\visual studio 2008\projects\project1\calculator\calculator\main_calculator.cpp(66) : error C2046: illegal case
c:\documents and settings\*********\my documents\visual studio 2008\projects\project1\calculator\calculator\main_calculator.cpp(77) : error C2046: illegal case
c:\documents and settings\*********\my documents\visual studio 2008\projects\project1\calculator\calculator\main_calculator.cpp(84) : error C2047: illegal default
I can't honestly figure it out ... I'd really, really like some help!
metalcrunch