| | |
c++ compilation error
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2007
Posts: 3
Reputation:
Solved Threads: 0
hi,
i am basically a newbie to C++ and tried to make this simple math program but came acroos this error and don't know how to resolve it:
the error is saying:
limac@limac-kubuntu:~/Desktop$ g++ -o math math.cpp
math.cpp:15:14: warning: multi-character character constant
math.cpp:23:20: warning: character constant too long for its type
math.cpp:31:20: warning: character constant too long for its type
math.cpp:39:20: warning: character constant too long for its type
math.cpp: In function ‘int main()’:
math.cpp:10: error: ‘Add’ was not declared in this scope
math.cpp:15: warning: overflow in implicit constant conversion
math.cpp:15: error: could not convert ‘input.std::basic_string<_CharT, _Traits, _Alloc>::operator= [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](100)’ to ‘bool’
math.cpp:23: warning: overflow in implicit constant conversion
math.cpp:23: error: could not convert ‘input.std::basic_string<_CharT, _Traits, _Alloc>::operator= [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](116)’ to ‘bool’
math.cpp:31: warning: overflow in implicit constant conversion
math.cpp:31: error: could not convert ‘input.std::basic_string<_CharT, _Traits, _Alloc>::operator= [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](121)’ to ‘bool’
math.cpp:39: warning: overflow in implicit constant conversion
math.cpp:39: error: could not convert ‘input.std::basic_string<_CharT, _Traits, _Alloc>::operator= [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](101)’ to ‘bool’
limac@limac-kubuntu:~/Desktop$
if anyone can identify the error and inform me, I'd really appreciate that!
Thx
i am basically a newbie to C++ and tried to make this simple math program but came acroos this error and don't know how to resolve it:
c++ Syntax (Toggle Plain Text)
#include <iostream> #include <cmath> #include <string> using namespace std; int main(void) { string input = Add; int a, b; cout << "What would you like to do? (Add, Subtract, Multiply, Divide) "; cin >> input; if (Add) { cout << "Enter a value: "; cin >> a; cout << "Enter another value: "; cin >> b; cout << "The sum of the numbers is " << a + b << endl; } else if (input = 'Subtract') { cout << "Enter a value: "; cin >> a; cout << "Enter another value: "; cin >> b; cout << "The difference of the two numbers is " << a - b << endl; } else if (input = 'Multiply') { cout << "Enter a value: "; cin >> a; cout << "Enter another value: "; cin >> b; cout << "The product of the two numbers is " << a * b << endl; } else if (input = 'Divide') { cout << "Enter a value: "; cin >> a; cout << "Enter another value: "; cin >> b; cout << "The quotient of the two numbers is " << a / b << endl; cout << "And the remainder is " << a % b << endl; } return 0; }
limac@limac-kubuntu:~/Desktop$ g++ -o math math.cpp
math.cpp:15:14: warning: multi-character character constant
math.cpp:23:20: warning: character constant too long for its type
math.cpp:31:20: warning: character constant too long for its type
math.cpp:39:20: warning: character constant too long for its type
math.cpp: In function ‘int main()’:
math.cpp:10: error: ‘Add’ was not declared in this scope
math.cpp:15: warning: overflow in implicit constant conversion
math.cpp:15: error: could not convert ‘input.std::basic_string<_CharT, _Traits, _Alloc>::operator= [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](100)’ to ‘bool’
math.cpp:23: warning: overflow in implicit constant conversion
math.cpp:23: error: could not convert ‘input.std::basic_string<_CharT, _Traits, _Alloc>::operator= [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](116)’ to ‘bool’
math.cpp:31: warning: overflow in implicit constant conversion
math.cpp:31: error: could not convert ‘input.std::basic_string<_CharT, _Traits, _Alloc>::operator= [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](121)’ to ‘bool’
math.cpp:39: warning: overflow in implicit constant conversion
math.cpp:39: error: could not convert ‘input.std::basic_string<_CharT, _Traits, _Alloc>::operator= [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](101)’ to ‘bool’
limac@limac-kubuntu:~/Desktop$
if anyone can identify the error and inform me, I'd really appreciate that!
Thx
Last edited by Ancient Dragon; Dec 29th, 2007 at 9:03 pm. Reason: add code tags
•
•
Join Date: Dec 2007
Posts: 113
Reputation:
Solved Threads: 4
There are a few issues. In the line, "string input = Add;", I don't think you need the Add there. All you need to do is initialize the string input.
The line if(Add) needs to be changed to "if(input == "Add").
Additionally, every if line needs to use ==, not =.
Lastly, all you need to do is use double quotes instead of single ones.
The line if(Add) needs to be changed to "if(input == "Add").
Additionally, every if line needs to use ==, not =.
Lastly, all you need to do is use double quotes instead of single ones.
Last edited by zoner7; Dec 29th, 2007 at 8:44 pm.
string input = Add; C++ Syntax (Toggle Plain Text)
if (Add)
else if (input = 'Subtract')- = is assign operator, and == is equalition operator.
- '' single quote is for single character, "" double quote use for string
Yesterday is a history, tomorrow is a mystery, today is a gift.
Behind every smile is a tear.
Visal .In
Behind every smile is a tear.
Visal .In
•
•
Join Date: Dec 2007
Posts: 1
Reputation:
Solved Threads: 0
The following is pretty much useless:
Change it to the following to just declare the var.
The entered value (Add, Subtract, Multiply, Divide) will be placed in the var input.
This means, you want to check which value was entered.
You could use the following to check it:
Hope this helps.
Kind regards,
Erik
C++ Syntax (Toggle Plain Text)
string input = Add;
Change it to the following to just declare the var.
C++ Syntax (Toggle Plain Text)
string input;
The entered value (Add, Subtract, Multiply, Divide) will be placed in the var input.
This means, you want to check which value was entered.
You could use the following to check it:
C++ Syntax (Toggle Plain Text)
if (!strcmp(input.c_str(), "Add")) { // do your code to add the values. } else if (!strcmp(input.c_str(), "Subtract")) { // do your code to subtract the values. }
Hope this helps.
Kind regards,
Erik
![]() |
Similar Threads
- compilation error (C++)
- Compilation error in graphml.cpp (C++)
- compilation error (C++)
- error message in outlook 2003 (Windows NT / 2000 / XP)
- Compilation Error (ASP.NET)
- Compilation error urgent? (VB.NET)
- Compilation Error Handles cmdLogin.ServerClick (ASP.NET)
- please help with these error problems (C++)
Other Threads in the C++ Forum
- Previous Thread: Removing numbers from a program.
- Next Thread: Can anyone help me using <graphics.h>
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





