Undeclared Identifier in second function? (C++) [closed] - c++

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I am having an issue with my C++ code. It keeps telling me Undeclared Identifier in the second function (the menu), but I cannot see the issue since I am passing the variable. The code is here

//Menu
void menu(int &selction) //TYPO!
{
cout << "Welcome to the math work along program!" << endl;
cout << "This will generate 2 numbers with the selected operator and\n allow you to solve the equation" << endl;
cout << "1. Addition\n2. Subtraction\n3. Multiplication\nOr type -1 to quit\n";
cin >> selection;
You have a typo. You've misspelled selection as selction

Related

Why does my c++ code keep printing a random number? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
Hi I need help with this code. It keeps on printing "ur input:32765" and the number keeps changing. I read a question on stack overflow and it said it wasn't initialized, whatever that means. Can someone help with whats wrong?
#include <iostream>
using namespace std;
int main() {
int x;
cout << "ur input:";
cin >> x;
cout << "" << x;
return 0;
}
Write
if (cin >> x){
cout << "" << x;
} else {
cout << "bad input";
}
otherwise a read of an unintialised x could arise if the cin fails in C++03 or earlier. That can happen if there are not data on the stream that can be read into an int type.

List of object in C++ [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I trying to save write a list of objects. I don't know how to check if the created object was really saved, for now I try to test it by calculating the list size
void Hash::insertTest(Customer *cl) {
int index = hashFunction(cl->code); //OK
clientes[index].push_back(*cl);
int sizetable = sizeof(clientes)/sizeof(clientes[0]); /// I Think this is wrong.
cout << "size" << sizetable << endl; //prints 0, no insert worked
}
List:
list<Customer> *clientes;
Full Code is here with a web compiler
No, already you did it :) Please check my comments and This source :)
void Hash::insertTest(Customer *cl) {
int index = hashFunction(cl->code); //OK
clientes[index].push_back(*cl);
int sizetable = sizeof(clientes)/sizeof(clientes[0]); /// I Think this is wrong.
cout << "size" << sizetable << endl; //prints 0, no insert worked
cout << "Look -> " << clientes[index].front().name<<endl; //// You already save client in this list.
}

How to get rid of this error? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I was assigned to do a simple number converter, I followed all the instructions and they seemed pretty straight forward. This is for a beginner course into C++ and I seem to be missing the mark on this program. I continue to get an error stating that I need an initializer before double inputedNumber or that the variable is not in the scope. I have even compared my code to classmates and did what they did but this error still happens...
Any help would be awesome!
Thanks in advance!
#include <iostream>
using namespace std;
int main()
{
double inputedNumber;
cout << "Please input a decimal to be converted.";
cin >> inputedNumber;
cin >> "Number Converter!! The given number is" >> inputedNumber;
}
cin >> "Number Converter!! The given number is" >> inputedNumber;
does not compile, since cin is only for input not output; use cout instead!
cout << "Number Converter!! The given number is" << inputedNumber;
Also, if you really want to convert a number (to an integer for example) use this:
cout << "Number Converter!! The given number is" << static_cast<int>(inputedNumber);
First Line in main function is missing a semicolon.

Confused writing this program [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
New to coding. The first part in the first link which is the character letter 'a' is correct. But then after that, its downhill from there.
Its showing me whats wrong, but I do not understand it.
You have declared several variables with the same name 'number' in the same scope. That is not allowed and leads to the error messages.
Within a scope (such as a function or loop or something), you can only declare a variable once. Otherwise, it would be ambiguous which one you were talking about.
The error is saying you've already declared a variable called number (as an int), and you cannot declare it again within the same scope.
Make the second variable called something else:
double dNumber = 1.11;
cout << "Please enter a double: " << dNumber << endl;
bool bNumber = 0;
cout << "Please enter a bool: " << bNumber << endl;
Note, it's usually more typical to set bool values to either true or false.
Now, if you really, really wanted to use the variable name number multiple times, you could put each section in curly braces:
{
double number = 1.11;
cout << "Please enter a double: " << number << endl;
}
{
bool number = 0;
cout << "Please enter a bool: " << number << endl;
}
In that case, you would no longer have access to that variable outside the curly braces, thus the reference is no longer ambiguous.

how to define int number using comparison operators [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I want to declare
int x = it must be more or equal to 1 but less or equal to 100;
How can I do it? I dont want to use if condition, Im looking for something short and clear, if possible.
The x number is input, so program should accept only numbers in this limit.
It seems that you're looking to error check on initialization.
If I were you I'd do something along the lines of.
int x;
cout << "Enter a value: " << flush;
cin >> x;
while(!((x>=1)&&(x<=100))) {
cout << "Try Again: " << flush;
cin >> x;
}