Problem with logical operator
1 2 3 4 5 6 7 8 9 10 11
|
void ne(){
cout << "bla bla";
cin >> b1;
cin >> b2;
if(b1 ! b2){
cout << "bla bla";
}
else {
cout << "bla bla";
}
}
|
Why wont this part of code ever compile?
1>------ Build started: Project: Program 13, Configuration: Debug Win32 ------
1>Compiling...
1>cpp.cpp
1>c:\documents and settings\drago\desktop\c++ programi\program 13\program 13\cpp.cpp(32) : error C2143: syntax error : missing ')' before '!'
1>c:\documents and settings\drago\desktop\c++ programi\program 13\program 13\cpp.cpp(32) : error C2059: syntax error : ')'
1>c:\documents and settings\drago\desktop\c++ programi\program 13\program 13\cpp.cpp(32) : error C2146: syntax error : missing ';' before identifier 'cout'
1>c:\documents and settings\drago\desktop\c++ programi\program 13\program 13\cpp.cpp(32) : warning C4552: '!' : operator has no effect; expected operator with side-effect
1>c:\documents and settings\drago\desktop\c++ programi\program 13\program 13\cpp.cpp(33) : error C2181: illegal else without matching if
1>Build log was saved at "file://c:\Documents and Settings\Drago\Desktop\C++ Programi\Program 13\Program 13\Debug\BuildLog.htm"
1>Program 13 - 4 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
|
!= (not equal) may be what you are looking for.
if(b1 != b2)
Last edited on
I think i said logical operator, not relational operator...
Last edited on
If it helps, this is whole thing:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
/*
Ovaj program demonstrira logiku
*/
#include <iostream>
#include <string>
using namespace std;
bool b1,b2;
string izbor;
void i(){
cout << "I: ";
cin >> b1;
cin >> b2;
if(b1&&b2) cout << "rjesenje je: tocno!\n";
else cout << "rjesenje je: netocno!\n";
}
void ili(){
cout << "Iskljucna disjunkcija: ";
cin >> b1;
cin >> b2;
if(b1||b2) cout << "rjesenje je: tocno!\n";
else cout << "rjesenje je: netocno!\n";
}
void ne(){
cout << "Ukljucna Disjunkcija: ";
cin >> b1;
cin >> b2;
if(b1 ! b2) cout << "rjesenje je: tocno!\n";
else cout << "rjesenje je: netocno!\n";
}
void upute(){
cout << "Ovaj program radi kao tablica za istinitosno vrednovanje slozenih izkaza.\n";
cout << "Trenutno program podrzava \"i\", iskljucnu disjunkciju i ukljucnu disjunkciju.\n";
cout << "Za \"i\" upisi \"i\", za iskljucnu disjunkciju \"ili\", a za ukljucnu disjunkciju \"ne\"\n";
cout << "Nakon sto izaberes jednu od opcija upisi 0 za netocno i 1 za tocno\n";
cout << "Za izlaz iz programa upisi \"exit\"";
}
int main(){
opet:
cin >> izbor;
if(izbor=="i") i();
else if(izbor=="ili") ili();
//else if(izbor=="ne") ne();
else if(izbor=="upute") upute();
else if(izbor=="izlaz") goto kraj;
else {
cout << "Nevaljan izbor, ako neznas kako koristiti program upisi \"upute\"\n";
goto opet;
}
goto opet;
kraj:
return 0;
}
|
I think i said logical operator, not relational operator... |
Yes, you did say logical but your code suggested something else maybe if you say what you want to do...
Last edited on
Sorry.
I wanted the program to act like "truth table" (in logics).
Last edited on
try: if ( (b1 || b2) && !(b1 && b2) )
Resolved. Thanks.
Topic archived. No new replies allowed.