Author Topic: Basic C++ Calculator  (Read 1585 times)

0 Members and 1 Guest are viewing this topic.

Offline Killeramor

  • Peasant
  • *
  • Posts: 115
  • Cookies: 5
  • Programming tutor for Qbasic, and beginner C++.
    • View Profile
Basic C++ Calculator
« on: October 15, 2014, 04:44:56 pm »

Here is an example of a basic C++ Calculator with function calls. It was an assignment for a Class.



Code: [Select]
#include <cstdlib>
#include <iostream>


using namespace std;


void subtract(float[],int);
void multiply(float[],int);
void add(float[],int);
void divide(float[],int);
void CalculatorWithFunctionCalls(int);


int main()
{
int length;
string name, feel;


cout<<"Hello, what is your first name? ";
    getline(cin,name);
cout<< "How are you, " << name<<" ? ";
    cin>> feel;
        if (feel == ("good")|| feel== ("Good") || feel==("alright")||
                feel==("ok")||  feel== ("Okay"))
            cout<< "That is good! Lets get started!"<<endl;
        else
            cout<<"Well I hope your day gets better!"<<endl;


cout<<"How many numbers would you like to input?";
    cin>> length;
   
    CalculatorWithFunctionCalls(length);
   
    system("PAUSE");
        return 0;
}


void CalculatorWithFunctionCalls(int length)

int counter ;
string answer;
float number[length];
char symbol;
bool again=false;


do
{
        for( counter= 0; counter <length;counter ++)
            {
            cout<<"Enter number "<<counter+1<<": ";
                cin>> number[counter];
            }
    cout<<"Enter a math symbol you would like(+,-,/,*): ";
        cin>> symbol;
           
    switch(symbol)
    {
        case '-':
        subtract(number,length);
        break;
        case '*':
        multiply(number,length);
        break;
        case '+':
        add(number,length);
        break;
        case '/':
        divide(number,length);
        break;
    }
        cout<<"Would you like to do another calculation?(Y or N) ";
            cin>> answer;
        if (answer == ("Y") || answer == ("y"))
            again=true;
        else if (answer == ("N") || ("n"))
            again=false;
        else
            cout<< "Invalid response";


}
while (again);


cout<<"Have a good day!\n";
}


void subtract(float num[] , int length)
{
int counter;
float temp=0;
    for (counter = 0; counter < length; counter++)
        {
            temp= (num[counter] - temp);
        }
           
       
cout<<"Your subtraction equation equals: " << temp<<endl;
}


void multiply(float num[] , int length)
{
int counter;
float temp=1;


    for (counter = 0; counter < length; counter++)
        {
            temp= (num[counter]* temp);
        }
           
cout<<"Your multiplication equation equals: " << temp<<endl;
}


void add(float num[] , int length)
{
int counter;
float temp;
    for (counter = 0; counter < length; counter++)
        {
            temp= (temp+ num[counter]);
        }
           
cout<<"Your addition equation equals: " << temp<<endl;
}


void divide(float num[] , int length)
{
int counter;
float temp=1;
    for (counter = 0; counter < length; counter++)
        {
            temp= (num[counter]/ temp);
        }
           
cout<<"Your division equation equals: " << temp<<endl;
}
Knowledge is free. Share what you know, help others grow. We all start somewhere.

Offline HTH

  • Official EZ Slut
  • Administrator
  • Knight
  • *
  • Posts: 395
  • Cookies: 158
  • EZ Titan
    • View Profile
Re: Basic C++ Calculator
« Reply #1 on: October 15, 2014, 07:30:06 pm »
Hey KillerAmor I hope you don't mind but I edited things a bit to show some programming concepts I think the forum could learn from :)

I removed the niceties I assume your prof required, and showed some dynamic memory allocation, as well as hungarian notation for variables. I also changed the functions you had to show our users how ig you ever have multiple similar functions to just combine them into one :D :)

I learn extremely well with before and afters and im sure others do too, there was nothing wrong with your code, just showing some concepts and I struggle at coding WITHOUT applying most concepts, so i can't do a before/after by myself :)

Code: [Select]

#include <cstdlib>
#include <iostream>

/*using namespace std;
This is convenient but is generally bad programming practice, you're saying USE STD FOR EVERYTHING
But 99% of the time all you really mean is: using std::cout; It's not awful and you certainly wont have an issue with it up till about... second or third year university level But it is worth mentioning

void subtract(float[],int);
void multiply(float[],int);
void add(float[],int);
void divide(float[],int);
was all replaced with:

Once again no real issue with that, it's just not exactly efficient, or
really required to have four functions which are only wrappers for basic operations
 
*/
float arithmeticOperation(char,float[],int);

int main()
{
    using std::cout;
    using std::cin;
    int iAgain = 1;
    int cNumbers; //HUngarian Notation for COUNT of Numbers
    cout<<"How many numbers would you like to input?";
    cin>>cNumbers;
    //float number[length]; This is allowed in C, but in C++ (assuming we still want to use this style of container..)
    //We do this
    float * rgfpNumbers = new float [cNumbers]; //This dynamically allocates a block of memory for cNumbers worth of flaots, and returns the pointer to the front.
    //If anyone cares rgfp is range(array) of floating point
    char chOper; //Once again a variable notation scheme helps alot ;p
   
    do
    {
            cout << "\nEnter number 1: ";
            for(int i = 0; i < cNumbers;)
            {
                cin    >> rgfpNumbers[i];
                cout << "\nEnter number "<< ++i <<": ";
            }
            do
            {
                cout<<"\nEnter a math symbol you would like(+,-,/,*): ";
                cin>>chOper;
                //Any time you are operating off of user input.. verify that shit!
            } while(!(chOper == '+' || chOper == '-' || chOper == '*' || chOper == '/'));
            cout << arithemeticOperation(chOper,rgfpNumbers,cNumbers);
            /*cout<<"Would you like to do another calculation?(Y or N) ";
            cin>> answer;
            if (answer == ("Y") || answer == ("y"))
                again=true;
            else if (answer == ("N") || ("n"))
                again=false;
            else
                cout<< "Invalid response";*/
            // You have to act upon the invalid responses
            do
            {
                cout << "Would you like to go again? (1 for yes, 0 for no)\n";
                cin >> iAgain;
            } while (!(iAgain == 1 || iAgain == 0));
    } while (iAgain);
    delete [] rgfpNumbers; //When using dynamic memory you have to delete it afterwards
    system("PAUSE");
    return 0;
}

float arithmeticOperation(char chOper, float rgfpNumbers[] , int cNumbers)
{
    float fpAnswer = 0;
    switch(chOper)
    {
        case '-':
            for (int i=0;i<cNumbers;i++)
                fpAnswer=(rgfpNumbers[i] - fpAnswer);
        break;
        case '*':
            for (int i=0;i<cNumbers;i++)
                fpAnswer=(rgfpNumbers[i] * fpAnswer);
        break;
        case '+':
            for (int i=0;i<cNumbers;i++)
                fpAnswer=(rgfpNumbers[i] + fpAnswer);
        break;
        case '/':
            for (int i=0;i<cNumbers;i++)
                fpAnswer=(rgfpNumbers[i] / fpAnswer);
    }
    return (fpAnswer);
}

« Last Edit: October 16, 2014, 04:17:31 pm by HTH »
<ande> HTH is love, HTH is life
<TurboBorland> hth is the only person on this server I can say would successfully spitefuck peoples women

Offline NoviParagon

  • /dev/null
  • *
  • Posts: 8
  • Cookies: 0
  • sal.paragon@gmail.com
    • View Profile
Re: Basic C++ Calculator
« Reply #2 on: October 16, 2014, 02:13:34 pm »
Hey KillerAmor I hope you don't mind but I edited things a bit to show some programming concepts I think the forum could learn from :)

<snip>

<some code>


Hey, I was just browsing this forum to look for code examples and stuff, and I came across this. I tried to compile your code but it didn't work. There were some errors and weird stuff which I changed, to get it working. I also opted to use vectors instead of C-style arrays, hopefully that won't draw too much ire...

should probably look at this in a proper editor so you can see everything.

(also this is my first post, so, ah....hello)

Code: (cpp) [Select]

#include <iostream>
#include <vector>    //needed for vectors, which we will use instead of c-style arrays

/*using namespace std;
This is convenient but is generally bad programming practice, you're saying USE STD FOR EVERYTHING
But 99% of the time all you really mean is: using std::cout; It's not awful and you certainly wont have an issue with it up till about... second or third year university level But it is worth mentioning

void subtract(float[],int);
void multiply(float[],int);
void add(float[],int);
void divide(float[],int);
was all replaced with:

Once again no real issue with that, it's just not exactly efficient, or
really required to have four functions which are only wrappers for basic operations
*/

double arithmeticOperation(char, std::vector<double>, int); //changed from type float to double for enhanced accuracy
   
int main()
{
    using std::cout;      //'using' directive put inside main - try to keep namespaces restrained to their relevant scope (which isn't always global)
    using std::cin;

    char iAgain = 'y';
    int  cNumbers = 0; //Hungarian Notation for COUNT of Numbers

    do{

        do {
            cout << "How many numbers would you like to input? ";
            cin >> cNumbers;
        } while (cNumbers < 2);    //this makes sure that we always have at least 2 numbers to operate on, as anything less would be meaningless
               
        char chOper; //Once again, a variable notation scheme really helps.

        std::vector<double> rgfpNumbers;    //we C++ now, no need for that new array stuff here
        //If anyone cares, "rgfp" is range (array) of floating point

   
        for (int i = 0; i < cNumbers; ++i)
        {
            double z = 0;
            cout << "\nEnter number " << i + 1 << ": ";
            cin >> z;
            rgfpNumbers.push_back(z);    //add the input to the end of the vector, new elements are created dynamically as needed
        }
       
        do
        {
            cout << "\nEnter a math symbol you would like(+,-,/,*): ";
            cin >> chOper;

        } while (!(chOper == '+' || chOper == '-' || chOper == '*' || chOper == '/')); //Any time you are operating off of user input... verify that shit!

        /*cout<<"Would you like to do another calculation?(Y or N) ";
            cin>> answer;
            if (answer == ("Y") || answer == ("y"))
            again=true;
            else if (answer == ("N") || ("n"))
            again=false;
            else
            cout<< "Invalid response";    You have to act upon the invalid responses */
       
        cout << "The result of the operation is: " << arithmeticOperation(chOper, rgfpNumbers, cNumbers) << std::endl;
       
       
        cout << "Would you like to go again? (input 'y' for yes, any other letter for no)\n";
        cin >> iAgain;
       
    } while (iAgain == 'y');
   

    //system("PAUSE"); NEBER EBER USE THIS!!!111!!!!1 (why? because "system" behavior is dependent on platform, in a different console on a different OS this may not work)
    cout << "~press enter to exit~";
    cin.get();   
    cin.ignore();    //simple alternative to using system, lets us look over the output before closing
    return 0;
}

double arithmeticOperation(char chOper, std::vector<double> rgfpNumbers, int cNumbers)    //made a new version of this, works a lot better
{
    double fpAnswer = 0;
    int i = 0;
    switch (chOper)
    {
    case '-':
        fpAnswer = rgfpNumbers[i];
        ++i;
        for (; i < cNumbers; i++)
            fpAnswer -= rgfpNumbers[i];
        break;
    case '*':
        fpAnswer = rgfpNumbers[i];
        ++i;
        for (; i < cNumbers; i++)
            fpAnswer *= rgfpNumbers[i];
    case '+':
        for (; i<cNumbers; i++)
            fpAnswer = (rgfpNumbers[i] + fpAnswer);
        break;
    case '/':
        fpAnswer = rgfpNumbers[i];
        ++i;
        for (; i < cNumbers; i++)
            fpAnswer /= rgfpNumbers[i];
    default:
        std::cout << "error in "<< __FUNCSIG__;        //because what if we do something like divide by zero?
    }
    return (fpAnswer);
}

/****************************************************************************
This code didn't do anything right except for addition, so I changed it a lot.
/////////////////////////////////////////////////////////////////////////////

float arithmeticOperation(char chOper, float rgfpNumbers[] , int cNumbers)
{
float fpAnswer = 0;
switch(chOper)
{
case '-':
for (int i=0;i<cNumbers;i++)
fpAnswer=(rgfpNumbers[i] - fpAnswer);
break;
case '*':
for (int i=0;i<cNumbers;i++)
fpAnswer=(rgfpNumbers[i] * fpAnswer);
break;
case '+':
for (int i=0;i<cNumbers;i++)
fpAnswer=(rgfpNumbers[i] + fpAnswer);
break;
case '/':
for (int i=0;i<cNumbers;i++)
fpAnswer=(rgfpNumbers[i] / fpAnswer);
}
return (fpAnswer);
}

********************************************************************************/
« Last Edit: October 16, 2014, 04:43:26 pm by NoviParagon »

Offline Killeramor

  • Peasant
  • *
  • Posts: 115
  • Cookies: 5
  • Programming tutor for Qbasic, and beginner C++.
    • View Profile
Re: Basic C++ Calculator
« Reply #3 on: October 16, 2014, 03:14:49 pm »
Hey KillerAmor I hope you don't mind but I edited things a bit to show some programming concepts I think the forum could learn from :)

I removed the niceties I assume your prof required, and showed some dynamic memory allocation, as well as hungarian notation for variables. I also changed the functions you had to show our users how ig you ever have multiple similar functions to just combine them into one :D :)

I learn extremely well with before and afters and im sure others do too, there was nothing wrong with your code, just showing some concepts and I struggle at coding WITHOUT applying most concepts, so i can't do a before/after by myself :)

Code: [Select]

#include <cstdlib>
#include <iostream>

/*using namespace std;
This is convenient but is generally bad programming practice, you're saying USE STD FOR EVERYTHING
But 99% of the time all you really mean is: using std::cout; It's not awful and you certainly wont have an issue with it up till about... second or third year university level But it is worth mentioning

void subtract(float[],int);
void multiply(float[],int);
void add(float[],int);
void divide(float[],int);
was all replaced with:

Once again no real issue with that, it's just not exactly efficient, or
really required to have four functions which are only wrappers for basic operations
 
*/
float arithmeticOperation(char,float[],int);

int main()
{
    using std::cout, std::cin;
    int iAgain = 1;
    int cNumbers; //HUngarian Notation for COUNT of Numbers
    cout<<"How many numbers would you like to input?";
    cin>>cNumbers;
    //float number[length]; This is allowed in C, but in C++ (assuming we still want to use this style of container..)
    //We do this
    float * rgfpNumbers = new float [cNumbers]; //This dynamically allocates a block of memory for cNumbers worth of flaots, and returns the pointer to the front.
    //If anyone cares rgfp is range(array) of floating point
    char chOper; //Once again a variable notation scheme helps alot ;p
   
    do
    {
            cout << "\nEnter number 1: ";
            for(int i = 0; i < cNumbers;)
            {
                cin    >> rgfpNumbers[i];
                cout << "\nEnter number "<< ++i <<": ";
            }
            do
            {
                cout<<"\nEnter a math symbol you would like(+,-,/,*): ";
                cin>>chOper;
                //Any time you are operating off of user input.. verify that shit!
            } while(!(chOper == '+' || chOper == '-' || chOper == '*' || chOper == '/'));
           
            /*cout<<"Would you like to do another calculation?(Y or N) ";
            cin>> answer;
            if (answer == ("Y") || answer == ("y"))
                again=true;
            else if (answer == ("N") || ("n"))
                again=false;
            else
                cout<< "Invalid response";*/
            // You have to act upon the invalid responses
            do
            {
                cout << "Would you like to go again? (1 for yes, 0 for no)\n";
                cin >> iAgain;
            } while (!(iAgain == 1 || iAgain == 0));
    } while (iAgain);
    delete [] rgfpNumbers; //When using dynamic memory you have to delete it afterwards
    system("PAUSE");
    return 0;
}

float arithmeticOperation(char chOper, float rgfpNumbers[] , int cNumbers)
{
    float fpAnswer = 0;
    switch(chOper)
    {
        case '-':
            for (int i=0;i<cNumbers;i++)
                fpAnswer=(rgfpNumbers[i] - fpAnswer);
        break;
        case '*':
            for (int i=0;i<cNumbers;i++)
                fpAnswer=(rgfpNumbers[i] * fpAnswer);
        break;
        case '+':
            for (int i=0;i<cNumbers;i++)
                fpAnswer=(rgfpNumbers[i] + fpAnswer);
        break;
        case '/':
            for (int i=0;i<cNumbers;i++)
                fpAnswer=(rgfpNumbers[i] / fpAnswer);
    }
    return (fpAnswer);
}



The professor did tell of to use Hungarian notation, but these codes were assignments I did not have to turn in so when written they were just thrown out. For the memory allocation, sadly that is where the class stopped on. It was our last day lecture that he did not talk much into. For the niceties, I do that personally because it always made my code stand out in the class. I helped other people code throughout the class so I had to add things in in case he ever looked at mine, and could tell it was truly mine. lol Thanks for the revamp. Printed the code out and cross referencing them both.
Knowledge is free. Share what you know, help others grow. We all start somewhere.

Offline HTH

  • Official EZ Slut
  • Administrator
  • Knight
  • *
  • Posts: 395
  • Cookies: 158
  • EZ Titan
    • View Profile
Re: Basic C++ Calculator
« Reply #4 on: October 16, 2014, 04:12:40 pm »
For the Record on the forum, I hadn't compiled my code, Im usually pretty prety good at geting it close to right the first time :P

I did go and compile it since you said there were odd errors and these were the errors using g++

test.cpp: In function ‘int main()’:
test.cpp:22:20: error: expected ‘;’ before ‘,’ token
test.cpp:22:20: error: expected primary-expression before ‘,’ token
test.cpp:26:5: error: ‘cin’ was not declared in this scope

So i guess it isn't valid to do multiple using's seperate by a comma. My bad, I genuinely knew that too but hey shit happens.

but thank you for using vectors as that's even more for people to compare to. You are incorrect on it being better to use a namespace declaration outside of main however. You should only declare namespaces for as wide of a scope as they are required.

I ammended my post to show this, i compiled whats up there now and it ran fine
« Last Edit: October 16, 2014, 04:15:58 pm by HTH »
<ande> HTH is love, HTH is life
<TurboBorland> hth is the only person on this server I can say would successfully spitefuck peoples women

Offline NoviParagon

  • /dev/null
  • *
  • Posts: 8
  • Cookies: 0
  • sal.paragon@gmail.com
    • View Profile
Re: Basic C++ Calculator
« Reply #5 on: October 16, 2014, 04:40:30 pm »
Hey HTH, thanks for the note about namespaces, you bring up a good point about keeping the 'using' directive in the relevant scope so I'll update my source to reflect that.

Offline Killeramor

  • Peasant
  • *
  • Posts: 115
  • Cookies: 5
  • Programming tutor for Qbasic, and beginner C++.
    • View Profile
Re: Basic C++ Calculator
« Reply #6 on: October 16, 2014, 05:37:56 pm »
I love the interaction on my Post.
::) 8) ;D ;D ::) ::)
Knowledge is free. Share what you know, help others grow. We all start somewhere.

Offline ArkPhaze

  • Peasant
  • *
  • Posts: 136
  • Cookies: 20
  • null terminated
    • View Profile
Re: Basic C++ Calculator
« Reply #7 on: October 19, 2014, 12:07:26 am »
Hey KillerAmor I hope you don't mind but I edited things a bit to show some programming concepts I think the forum could learn from :)

I removed the niceties I assume your prof required, and showed some dynamic memory allocation, as well as hungarian notation for variables. I also changed the functions you had to show our users how ig you ever have multiple similar functions to just combine them into one :D :)

I learn extremely well with before and afters and im sure others do too, there was nothing wrong with your code, just showing some concepts and I struggle at coding WITHOUT applying most concepts, so i can't do a before/after by myself :)

Code: [Select]

#include <cstdlib>
#include <iostream>

/*using namespace std;
This is convenient but is generally bad programming practice, you're saying USE STD FOR EVERYTHING
But 99% of the time all you really mean is: using std::cout; It's not awful and you certainly wont have an issue with it up till about... second or third year university level But it is worth mentioning

void subtract(float[],int);
void multiply(float[],int);
void add(float[],int);
void divide(float[],int);
was all replaced with:

Once again no real issue with that, it's just not exactly efficient, or
really required to have four functions which are only wrappers for basic operations
 
*/
float arithmeticOperation(char,float[],int);

int main()
{
    using std::cout;
    using std::cin;
    int iAgain = 1;
    int cNumbers; //HUngarian Notation for COUNT of Numbers
    cout<<"How many numbers would you like to input?";
    cin>>cNumbers;
    //float number[length]; This is allowed in C, but in C++ (assuming we still want to use this style of container..)
    //We do this
    float * rgfpNumbers = new float [cNumbers]; //This dynamically allocates a block of memory for cNumbers worth of flaots, and returns the pointer to the front.
    //If anyone cares rgfp is range(array) of floating point
    char chOper; //Once again a variable notation scheme helps alot ;p
   
    do
    {
            cout << "\nEnter number 1: ";
            for(int i = 0; i < cNumbers;)
            {
                cin    >> rgfpNumbers[i];
                cout << "\nEnter number "<< ++i <<": ";
            }
            do
            {
                cout<<"\nEnter a math symbol you would like(+,-,/,*): ";
                cin>>chOper;
                //Any time you are operating off of user input.. verify that shit!
            } while(!(chOper == '+' || chOper == '-' || chOper == '*' || chOper == '/'));
            cout << arithemeticOperation(chOper,rgfpNumbers,cNumbers);
            /*cout<<"Would you like to do another calculation?(Y or N) ";
            cin>> answer;
            if (answer == ("Y") || answer == ("y"))
                again=true;
            else if (answer == ("N") || ("n"))
                again=false;
            else
                cout<< "Invalid response";*/
            // You have to act upon the invalid responses
            do
            {
                cout << "Would you like to go again? (1 for yes, 0 for no)\n";
                cin >> iAgain;
            } while (!(iAgain == 1 || iAgain == 0));
    } while (iAgain);
    delete [] rgfpNumbers; //When using dynamic memory you have to delete it afterwards
    system("PAUSE");
    return 0;
}

float arithmeticOperation(char chOper, float rgfpNumbers[] , int cNumbers)
{
    float fpAnswer = 0;
    switch(chOper)
    {
        case '-':
            for (int i=0;i<cNumbers;i++)
                fpAnswer=(rgfpNumbers[i] - fpAnswer);
        break;
        case '*':
            for (int i=0;i<cNumbers;i++)
                fpAnswer=(rgfpNumbers[i] * fpAnswer);
        break;
        case '+':
            for (int i=0;i<cNumbers;i++)
                fpAnswer=(rgfpNumbers[i] + fpAnswer);
        break;
        case '/':
            for (int i=0;i<cNumbers;i++)
                fpAnswer=(rgfpNumbers[i] / fpAnswer);
    }
    return (fpAnswer);
}


There's still a few issues I can see:
1. 'arithemeticOperation' is different from 'arithmeticOperation' -- you call a function that doesn't exist (easy fix)
2. std::cin can fail with the insertion operator, and no correction or check is made for this which will result in infinite loops in your code for invalid input
3. Although it's at the end of the program, I still never get why people are taught to, or by preference, use system("pause"), and including a whole new header file to use it could be avoided if methods from <iostream> were used instead since it's already included.
« Last Edit: October 19, 2014, 12:14:26 am by ArkPhaze »
sig=: ArkPhaze

[ J/ASM/.NET/C/C++ - Software Engineer ]

Offline HTH

  • Official EZ Slut
  • Administrator
  • Knight
  • *
  • Posts: 395
  • Cookies: 158
  • EZ Titan
    • View Profile
Re: Basic C++ Calculator
« Reply #8 on: October 19, 2014, 01:38:56 am »
It's insane that g++ didn't catch that.. does it include a spellchecker? lol, seriously if so thats kinda cool


The cin part was totally an oversight on my part, teach me not to code while tired :D


The last bit, meh I just left it tbh
<ande> HTH is love, HTH is life
<TurboBorland> hth is the only person on this server I can say would successfully spitefuck peoples women

Offline ArkPhaze

  • Peasant
  • *
  • Posts: 136
  • Cookies: 20
  • null terminated
    • View Profile
Re: Basic C++ Calculator
« Reply #9 on: October 19, 2014, 05:18:12 am »
It's insane that g++ didn't catch that.. does it include a spellchecker? lol, seriously if so thats kinda cool

:S Why do you say it doesn't catch it? This would be an unresolved function call, which would definitely trigger a compiler error.

Ex:
Code: [Select]
#include <iostream>

void test() {}

#pragma GCC diagnostic ignored "-Wunused-parameter"
int main(int argc, char const *argv[])
{
  tst();
}

Code: [Select]
main.cpp: In function 'int main(int, const char**)':
main.cpp:8:7: error: 'tst' was not declared in this scope
   tst();
       ^
[Finished in 0.2s]

You defined a function prototype for 'arithmeticOperation':
Code: [Select]
float arithmeticOperation(char,float[],int);
But you called 'arithemeticOperation':
Code: [Select]
cout << arithemeticOperation(chOper,rgfpNumbers,cNumbers);
Here's how I would've done it:
Code: [Select]
#include <iostream>

int main()
{
  float arr[] = { 1.0f, 2.0f, 3.0f };
  float result = 1.0f;
  for (const auto &it : arr)
    result *= it;
  std::cout << result << std::endl;
}

Range based iterators. :)
« Last Edit: October 19, 2014, 05:37:42 am by ArkPhaze »
sig=: ArkPhaze

[ J/ASM/.NET/C/C++ - Software Engineer ]