I tried to write a basic calculator program, Visual basic finds 1 error. I cant find it.
Please help. I am kind off new to programming.

#include <iostream>
using namespace std;

int main(void)
{
	system("TITLE calculator");
	system("COLOR 9");
	char cChar;
	double dfirstnumber;
	double dsecondnumber;
	char cDoagain;

do
{
	 system("CLS");
	 cout << "please enter the first number that you would like to use" << endl;
	 cin >> dfirstnumber;
	 
	 cout << "please enter the operation that you would like to complete" << " (+,-,* or /) " << endl;
	 cin >> cChar;

	 cout << "please enter the second number you would like to use" << endl;
	 cin >> dsecondnumber;

	 switch (cChar)
	 {
		case '+':
			cout << " the answer is: " << dfirstnumber << " + " << dsecondnumber << " = " << 
	     	   (dfirstnumber + dsecondnumber) << endl;
			break;

		case '-':
			 cout << "the answer is: " << dfirstnumber << " - " << dsecondnumber << " = " << 
			    (dfirstnumber - dsecondnumber) << endl;
	 		break;
	
	                case '*':
			 cout << "the answer is: " << dfirstnumber << " * " << dsecondnumber << " = " << 
			    (dfirstnumber * dsecondnumber) << endl;
			break;
		case 'X':
			 cout << "the answer is: " << dfirstnumber << " X " << dsecondnumber << " = " << 
			    (dfirstnumber * dsecondnumber) << endl;
			break;
	                case 'x':
			 cout << "the answer is: " << dfirstnumber << " x " << dsecondnumber << " = " << 
			    (dfirstnumber * dsecondnumber) << endl;
			break;
	
		case '/':
		 if (dsecondnumber == 0) {
			 cout << " that is invalid " << endl;
		 }else{
		     cout << "the answer is: " << dfirstnumber << "/" << dsecondnumber << "=" << 
		     (dfirstnumber / dsecondnumber) << endl;
		 }	
	
		 break;	
	 default 
		 cout << "that is an invalid operation" << endl;
	     break;
	 }
	 cout << "would you like to start again? (y or n)" << endl;
                   cin >> cDoagain;

	}while (cDoagain == 'y' || cDoagain == 'Y');
	
	system("PAUSE");
	
    return 0;
}

Recommended Answers

All 5 Replies

I am very surprised that Visual Basic found only one error considering this code isn't written in Visual Basic ... it's written in C++.

line 60 - Error 1 error C2065: 'default' : undeclared identifier d:\COSC1436\temp\temp.cpp 60

and line 60 - Error 2 error C2146: syntax error : missing ';' before identifier 'cout' d:\COSC1436\temp\temp.cpp 60


this is what I found when trying to compile in C++

Greg

You need to add a colon after your default statement on line 59.

You need to describe the error. No one is going to spend an hour trying to find the error, then pour over your code to fix it. You need to describe the error and the circumstances with which it happens.

thanks guys.

sorry about the mistakes on the post and not descrbing the error, I was in a hurry before school, so I just did a quick post.

line 59 needed ";" after default

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.