Definitions and Code

Hi again! Ive got a problem with a piece of code. Would anyone please check it out and see what I did wrong? The code is below:
||
\/
#include <iostream>
#include <string>
int main()
{
using std::cout;
using std::cin;
using std::string;
string choice;
long int numchoice, answer, tempnum = 0;
cout << "This is a program taking the features of the WHILE and INCREMENT statements to the limit. Enjoy!";
cout << "\nWould you like to start?\n\n:: ";
cin >> choice;
if (choice == "yes") {
cout << "\nOke, let's begin!";
cout << "\n\nType in a number to add to the 'increment list', and type 'exit' to finally add all the numbers.";
while (numchoice != "exit") {
cin >> tempnum;
if (tempnum != "exit") {
tempnum++;
tempnum = numchoice;
}
while (tempnum != 0) {
answer += tempnum;
tempnum--;
}
}
cout << "The answer to your numbers are " << answer << ".";
cout << "Thank you, sir, for using this wonderful programme!";
}
return 0;
}


And now for the definition part. There are an array of words that I do not know the definition of. I tried them on google, but alas, those definitions were for adults. :(
Words I do not know:
1) omit
2) data type (yes, i know, unbelievable)
3) operand
4) binary operator (type of operator)
5) logical operator (another type of operator...)
6) [any other types of operators? Plus definitions please :)]
7) exponent

Thats the list of definitions I don't know. And some other problems: WHAT ARE A.L.L THE VARIABLE TYPES? Such as long, short, char, etc. I bet there are TONS more.

Last, but not least, why are variable declarations allowed outside of the main {}? I've seen it with my own eyes. Any help please?

Thanks!
You should start by reading this: http://www.cplusplus.com/doc/tutorial/variables/
alas, those definitions were for adults. :(

Okay, let's try to be simple

omit is a plain English word, it means skip, delete, ignore

data type is well, a type. A category. A way to classify data. Data of the same type have the same range of acceptable value and the same things can be done to any value of the same type.

operand is what you give an operator (say, in "2+3" 2 and 3 are the operands

binary operator is one that takes two operands (addition, assignment, greater-than)

logical operator is one that performs a logic operator (and, or, not, xor)

there are quite a few others, just look at a table, say http://en.cppreference.com/w/cpp/language/operator_precedence

Exponent is another name for power. It's how many times a number is multiplied with itself, when it's raised to some power (exponentiated)

Yes, C++ has quite a few built-in types. Here's a chart: http://home.roadrunner.com/~hinnant/TypeHiearchy.pdf

Variable can be declared outside of main(). They become accessible from every function in the same source file, and this is bad practice.

As for your program, numchoice is an number (the type is long int), but you're comparing it with the string literal "exit" (the type is const char[5]). That doesn't compile.
Last edited on
@Cubbi
That helped a lot! But now I have to ask. What is a string literal? :P I suck at these
A literal is a value that's not in a variable: integer literals are numbers like 1 or -10. Floating-point literals are numbers like 3.14. Boolean literals are true and false. A string literal is a bunch of characters surrounded by double quotes, like "Hello, world".
Topic archived. No new replies allowed.