I have to create a simple calculator and I dont know what I am doing wrong!
The code I have so far, there are 23 errors I got it down from 42! Now I am stuck and dont know which way is up or down!

#include <cstdlib>
#include <iostream>
#include <cmath>
#include <string>

using namespace std;


namespace  calcu{ 
	fNumbr = 0; 
	sNumbr = 0;
	enum menOptions {Exit, Addition, Subtraction, Division, Multiplcation, Modulus};


int main(void){
	cout<<endl<<"A simple calculator!\n";
	cout<<endl<<"Enter first number: \n";
	cin>>firstNumber;
	cout<<endl<<"Enter the second number: \n";
	cin>>secondNumber;

	int usersChoice=0;

	cout<<endl<<"Choose your calculation option:\n\n";
	cout << "Choose a Calculation Option:\n\n";
	cout << calcu::Addition<<" - Addition\n";
	cout << calcu::subtraction<<" - Subtraction\n";
	cout << calcu::division<<" - Division\n";
	cout << calcu::multiplcation<<" - Multiplcation\n";
	cout << calcu::modulus<<" - Modulus\n";
	cout << calcu::Exit << " - Exit\n";
	cout << "Enter a number: ";
	cin >> usersChoice;
	if (usersChoice < 0 || usersChoice > 5){
		cout << endl << "Invalid choice - program terminated\n\n";

		struct calcuType {double addition; double subtraction; double division; double multiplcation double modulus;};
		calcuType myCalcu;
		myCalcu.addition = fNumbr+sNumbr;
		myCalcu.subtraction = fNumbr-sNumbr;
		myCalcu.division = fNumbr/sNumbr; 
		myCalcu.multiplcation = fNumbr*sNumbr; 
		myCalcu.modulus = fsum(fNumbr,sNumbr);
		switch (usersChoice) {
						   case calcu::Exit:
							   cout << endl << "You choose to exit the program\n\n"; break;
						   case  calcu::Addition:
							   cout << endl
								   << "     "
								   << fNumbr
								   << " + "
								   <<"     "
								   << sNumbr
								   <<myCalcu.addition << "\n\n"; break;
						   case  calcu::subtraction:
							   cout << endl
								   << "     "
								   << fNumbr
								   << " - "
								   <<"     "
								   << sNumbr
								   <<myCalcu.subtraction << "\n\n"; break;
						   case  calcu::division:
							   cout << endl
								   << "     "
								   << fNumbr
								   << " / "
								   <<"     "
								   << sNumbr
								   <<myCalcu.division << "\n\n"; break;
						   case  calcu::multiplcation:
							   cout << endl
								   << "     "
								   << fNumbr
								   << " * "
								   <<"     "
								   << sNumbr
								   <<myCalcu.multiplcation << "\n\n"; break;
						   case  calcu::modulus:
							   cout << endl
								   << "     "
								   << fNumbr
								   << " % "
								   <<"     "
								   << sNumbr
								   <<myCalcu.modulus << "\n\n"; break;
						   default:
							   cout << endl << "Not a valid choose!\n\n";
							   {

		cout << endl << endl << "end of program\n\n";
	}

	return 0;

Edited 6 Years Ago by WaltP: Added CODE Tags

What are the errors? Find the first one and fix it and many of the later ones will fall away...

Here is a screenie

I dont know what half these mean. and if I try something to fix it to be corrected then another damn error pops up. Been at this since 10 am this morning. this is the lowest build of errors I have gotten too.

Edited 6 Years Ago by sofakingjewish: n/a

Attachments screen.png 53.82 KB

The variables on 10 and 11 (thanks WaltP!) have no type. I would first bring them into main and give them a type.

I would move the struct you declare up and out of main. It's not incorrect to put it in main but personally I think it keeps it better organized outside. EDIT: I realized it was your enum you were referencing in the menu part, so disregard that.

Edited 6 Years Ago by jonsca: n/a

The variables on 10 and 11 (thanks WaltP!) have no type. I would first bring them into main and give them a type.

I would move the struct you declare up and out of main. It's not incorrect to put it in main but personally I think it keeps it better organized outside. EDIT: I realized it was your enum you were referencing in the menu part, so disregard that.

thanks now down to 16 errors!

#include <cstdlib>
#include <iostream>
#include <cmath>
#include <string>

using namespace std;


namespace  calcu{ 
	fNumbr = 0; 
	sNumbr = 0;
	addition;
	subtraction;
	division;
	multiplcation;
	modulus;
	fSum;
	enum menOptions {Exit, Addition, Subtraction, Division, Multiplcation, Modulus};


	int main(void){
		int fNumbr=0;
		int sNumbr=0;
		int usersChoice=0;
		int addition;
		int subtraction;
		int division;
		int multiplcation;
		int modulus;
		int fSum;


		cout<<endl<<"A simple calculator!\n";
		cout<<endl<<"Enter first number: \n";
		cin>>fNumbr;
		cout<<endl<<"Enter the second number: \n";
		cin>>sNumbr;



		cout<<endl<<"Choose your calculation option:\n\n";
		cout << "Choose a Calculation Option:\n\n";
		cout << calcu::addition<<" - Addition\n";
		cout << calcu::subtraction<<" - Subtraction\n";
		cout << calcu::division<<" - Division\n";
		cout << calcu::multiplcation<<" - Multiplcation\n";
		cout << calcu::modulus<<" - Modulus\n";
		cout << calcu::Exit << " - Exit\n";
		cout << "Enter a number: ";
		cin >> usersChoice;
		if (usersChoice < 0 || usersChoice > 5){
			cout << endl << "Invalid choice - program terminated\n\n";

			struct calcuType {double addition; double subtraction; double division; double multiplcation double modulus;};
			calcuType myCalcu;
			myCalcu.addition = fNumbr+sNumbr;
			myCalcu.subtraction = fNumbr-sNumbr;
			myCalcu.division = fNumbr/sNumbr; 
			myCalcu.multiplcation = fNumbr*sNumbr; 
			myCalcu.modulus = fSum(fNumbr/sNumbr);
			switch (usersChoice) {
						   case calcu::Exit:
							   cout << endl << "You choose to exit the program\n\n"; break;
						   case  calcu::Addition:
							   cout << endl
								   << "     "
								   << fNumbr
								   << " + "
								   <<"     "
								   << sNumbr
								   <<myCalcu.addition << "\n\n"; break;
						   case  calcu::subtraction:
							   cout << endl
								   << "     "
								   << fNumbr
								   << " - "
								   <<"     "
								   << sNumbr
								   <<myCalcu.subtraction << "\n\n"; break;
						   case  calcu::division:
							   cout << endl
								   << "     "
								   << fNumbr
								   << " / "
								   <<"     "
								   << sNumbr
								   <<myCalcu.division << "\n\n"; break;
						   case  calcu::multiplcation:
							   cout << endl
								   << "     "
								   << fNumbr
								   << " * "
								   <<"     "
								   << sNumbr
								   <<myCalcu.multiplcation << "\n\n"; break;
						   case  calcu::modulus:
							   cout << endl
								   << "     "
								   << fNumbr
								   << " % "
								   <<"     "
								   << sNumbr
								   <<myCalcu.modulus<<FSum<<"\n\n"; break;
						   default:
							   cout << endl << "Not a valid choose!\n\n";
							   {

								   cout << endl << endl << "end of program\n\n";
							   }

							   return 0;

.

Edited 6 Years Ago by sofakingjewish: n/a

Attachments scree1n.png 43.83 KB

Go back and pop some code tags around your code, use the edit button and either highlight and press the [code] button in the box, or type the following around your code:
[noparse][code] //code goes here [/code][/noparse].
WaltP (faithful moderator) put them around your last post but try to remember them on your own.

My own clarification:

EDIT: I realized it was your enum you were referencing in the menu part, so disregard that.

I meant that to mean disregard the part I had written previously about using the struct before you declared it.

Okay, so -- remove the entire part between namespace and the enum. To declare a struct up there write the [icode] struct yada {};[/icode] bits around it just like you did when you had it in main.

Here's a hint: look how you've written the names in the enum and look at how you wrote the names when you used them.

Edited 3 Years Ago by Dani: Formatting fixed

So I went from 16 errors to 62. GDI! What am I missing? the struct stuff should be things like my menus? or?

#include <cstdlib>
#include <iostream>
#include <cmath>
#include <string>

using namespace std;


namespace

enum menOptions {exit, addition, subtraction, division, multiplcation, modulus};


int main(void){
    int fNumbr=0;
    int sNumbr=0;
    int usersChoice=0;
    int addition;
    int subtraction;
    int division;
    int multiplcation;
    int modulus;
    int fSum;

    struct calcu {};


    cout<<endl<<"A simple calculator!\n";
    cout<<endl<<"Enter first number: \n";
    cin>>fNumbr;
    cout<<endl<<"Enter the second number: \n";
    cin>>sNumbr;



    cout<<endl<<"Choose your calculation option:\n\n";
    cout << "Choose a Calculation Option:\n\n";
    cout << calcu::addition<<" - Addition\n";
    cout << calcu::subtraction<<" - Subtraction\n";
    cout << calcu::division<<" - Division\n";
    cout << calcu::multiplcation<<" - Multiplcation\n";
    cout << calcu::modulus<<" - Modulus\n";
    cout << calcu::Exit << " - Exit\n";
    cout << "Enter a number: ";
    cin >> usersChoice;
    if (usersChoice < 0 || usersChoice > 5){
        cout << endl << "Invalid choice - program terminated\n\n";

        struct calcuType {double addition; double subtraction; double division; double multiplcation double modulus;};
        calcuType myCalcu;
        myCalcu.addition = fNumbr+sNumbr;
        myCalcu.subtraction = fNumbr-sNumbr;
        myCalcu.division = fNumbr/sNumbr; 
        myCalcu.multiplcation = fNumbr*sNumbr; 
        myCalcu.modulus = fSum(fNumbr/sNumbr);
        switch (usersChoice) {
                           case calcu::Exit:
                               cout << endl << "You choose to exit the program\n\n"; break;
                           case  calcu::Addition:
                               cout << endl
                                   << "     "
                                   << fNumbr
                                   << " + "
                                   <<"     "
                                   << sNumbr
                                   <<myCalcu.addition << "\n\n"; break;
                           case  calcu::subtraction:
                               cout << endl
                                   << "     "
                                   << fNumbr
                                   << " - "
                                   <<"     "
                                   << sNumbr
                                   <<myCalcu.subtraction << "\n\n"; break;
                           case  calcu::division:
                               cout << endl
                                   << "     "
                                   << fNumbr
                                   << " / "
                                   <<"     "
                                   << sNumbr
                                   <<myCalcu.division << "\n\n"; break;
                           case  calcu::multiplcation:
                               cout << endl
                                   << "     "
                                   << fNumbr
                                   << " * "
                                   <<"     "
                                   << sNumbr
                                   <<myCalcu.multiplcation << "\n\n"; break;
                           case  calcu::modulus:
                               cout << endl
                                   << "     "
                                   << fNumbr
                                   << " % "
                                   <<"     "
                                   << sNumbr
                                   <<myCalcu.modulus<<FSum<<"\n\n"; break;
                           default:
                               cout << endl << "Not a valid choose!\n\n";
                               {

                                   cout << endl << endl << "end of program\n\n";
                               }

                               return 0;

Edited 3 Years Ago by Dani: Formatting fixed

Attachments scre3en.png 49.86 KB scree2n.jpg 360.38 KB

I meant for you to stick the double addition; in between the { }. I wrote it out shorthand since you'd already had the right syntax when you had declared it in main.

Take a step back and look things up if you have to (or if they don't seem right).

@ThePMan I was just happy that we got the line numbers lol.

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