c++ - g++ problems, possibly with && operator -


i took c++ course during first year of college , stay sharp on fundamentals. used g++ trying use can continue use terminal commands necessary school's way of programming. code wrote:

#include <iostream> using namespace std;  int main() {     (int = 0; < 100; i++){         if ((i % 3) == 0) && ((i % 5) == 0){             cout << "fish , chips" << endl;}         else if ((i % 3) == 0){             cout << "fish" << endl;}         else if ((i % 5) == 0){             cout << "chips" << endl;}         else {cout << << endl;}     }  return 0; } 

and following error:

fish.cpp: in function ‘int main()’: fish.cpp:7:24: error: expected identifier before ‘(’ token    if ((i % 3) == 0) && ((i % 5) == 0){                         ^ fish.cpp:7:24: error: expected ‘;’ before ‘(’ token 

i believe g++ isn't recognizing '&&' operator. have advice?

your parentheses incorrect. && ((i % 5) == 0) parsed separate expression.

if ((i % 3) == 0) && ((i % 5) == 0) //change if (((i % 3) == 0) && ((i % 5) == 0)) //or maybe more readable if ((i % 3 == 0) && (i % 5 == 0)) 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -