Identifier not declared?

Discussion in 'C++' started by eli m, Mar 11, 2013.

  1. eli m

    eli m Guest

    I am trying to call these two functions and it says identifier not declared.
    My code is this:


    #include <iostream>
    #include <string>
    #include <fstream>
    #include <cmath>
    #include <stdlib.h>
    using namespace std;
    int main() {
    int run = 0;
    string function, mathop;
    int x, y;
    cout << "Type in help for a list of functions\n";
    //Start main loop
    while (run == 0) {
    cout << "Type in a function:";
    cin >> function;
    //Math function
    if (function == "math") {
    int mathloop;
    mathloop = 0;
    //Start while loop for math function
    while (mathloop == 0) {
    cout << "What math operation do you want to use?";
    cin >> mathop;
    // Multiplication Math Function
    if (mathop == "multiplication") {
    int mfirstnum, msecondnum;
    float ans;
    cout << "Type in your first number:";
    cin >> mfirstnum;
    cout << "Multiply your first number by:";
    cin >> msecondnum;
    ans = mfirstnum * msecondnum;
    cout << ans << "\n"; }
    //Break out of mathloop if main is entered
    else if (mathop == "main") {
    mathloop = 1; }
    //Division Math function
    else if (mathop == "division") {
    int dfirstnum, dsecondnum;
    float ans;
    cout << "Type in your first number:";
    cin >> dfirstnum;
    cout << "Divide your first number by:";
    cin >> dsecondnum;
    ans = dfirstnum / dsecondnum;
    cout << ans << "\n"; }
    //Addition Math Function
    else if (mathop == "addition") {
    int afirstnum, asecondnum;
    float ans;
    cout << "Type in your first number:";
    cin >> afirstnum;
    cout << "Add your first number by:";
    cin >> asecondnum;
    ans = afirstnum + asecondnum;
    cout << ans << "\n"; }
    //Exponent Math Function
    else if (mathop == "exponent") {
    double efirstnum, esecondnum;
    float ans;
    cout << "Type in your first number:";
    cin >> efirstnum;
    cout << "Multiply your first number by the power of:";
    cin >> esecondnum;
    ans = pow(efirstnum,esecondnum);
    cout << ans << "\n"; }
    //Subtraction Math Function
    else if (mathop == "subtraction") {
    float ans;
    cout << "Type in your first number:";
    x = getIntx();
    cout << "Subtract your first number by:";
    y = getInty();
    ans = x - y;
    cout << ans << "\n"; }
    //Catch Invalid Math Functions
    else {
    cout << "Not a valid math function" << "\n"; }
    }
    }
    //Help Function
    else if (function == "help") {
    string line;
    //Open File For Docs
    ifstream myfile ("documentation.txt");
    if (myfile.is_open())
    {
    while ( myfile.good() )
    {
    getline (myfile,line);
    cout << line << endl;
    }
    myfile.close();
    }

    else cout << "Unable to open file\n";
    }
    //Random Function
    else if (function == "random") {
    int randomloop = 0;
    string randfunc;
    while (randomloop == 0) {
    cout << "Random function to use:";
    cin >> randfunc;
    //Random Number Function
    if (randfunc == "number") {
    int x, y, rnum;
    cout << "Minimum number:";
    x = getIntx();
    cout << "Maximum number:";
    y = getInty();
    rnum = rand() % x + y;
    cout << rnum << "\n"; }
    //Break out of randomloop if main is entered
    else if (randfunc == "main") {
    randomloop = 1; }
    //Catch invalid random functions
    else {
    cout << "Not a valid random function" << "\n"; }
    }
    }
    }
    }
    //IIF
    int getIntx(){
    int x = 0;

    while(!(cin >> x)){
    cin.clear();
    cin.ignore(numeric_limits<streamsize>::max(),'\n');
    cout << "Invalid input. Try again: ";
    }

    return x;
    }


    int getInty(){
    int y = 0;

    while(!(cin >> y)){
    cin.clear();
    cin.ignore(numeric_limits<streamsize>::max(),'\n');
    cout << "Invalid input. Try again: ";
    }

    return y;
    }

    Why is it saying identifier not declared for getIntx and getInty when i try to call them?
     
    eli m, Mar 11, 2013
    #1
    1. Advertising

  2. eli m

    eli m Guest

    Nevermind, i figured it out.
     
    eli m, Mar 12, 2013
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. JohnZing

    declared or not declared ?

    JohnZing, Feb 5, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    1,624
    Jon Paal
    Feb 5, 2006
  2. Kobu
    Replies:
    7
    Views:
    502
  3. Replies:
    2
    Views:
    1,847
  4. Replies:
    2
    Views:
    950
    Owen Jacobson
    Dec 11, 2007
  5. S_K
    Replies:
    0
    Views:
    694
Loading...

Share This Page