Identifier not declared?


E

eli m

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?
 
Ad

Advertisements


Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top