Sunday, August 2, 2009

Whats the mistake in this c++ program.?

#include%26lt;iostream%26gt;





int main()





{


std::cout %26lt;%26lt; " X = " %26lt;%26lt; '\n';





int x;


std::cin%26gt;%26gt;x;


std::{cout %26lt;%26lt; "n= " %26lt;%26lt; '\n';





int n;


std::cin%26gt;%26gt; n;





int ans = x^n;


std::cout %26lt;%26lt; "Answer: " %26lt;%26lt; ans %26lt;%26lt; '\n';





return 0;


}


--------------------------------------...


this is giving error ---------------





Parse Error, expecting `'}''


':cout %26lt;%26lt; " X = "%26lt;%26lt; '\n''


aborting compile

Whats the mistake in this c++ program.?
std::{cout %26lt;%26lt; "n= " %26lt;%26lt; '\n';


remove { bracket from there





std::cout %26lt;%26lt; "n= " %26lt;%26lt; '\n';


it will not give you parse error since number of opening bracket must be equal to closing bracket
Reply:1)you left the ".h" in the header file


2)std::{cout %26lt;%26lt; "n= " %26lt;%26lt; '\n'; // unwanted open braket


std::cout %26lt;%26lt; "n= " %26lt;%26lt; '\n'; //change to this one





best if you declare the int x and n int begining to avoid mistake





Hope it helps you.................♪♪♪♪♪♪♪♪
Reply:I use turbo C compiler. It does not accept std::cout.


So i have made some changes to make it run properly.





The error was


You have used { unnecessarily in cout.





#include%26lt;iostream.h%26gt;





int main()





{


cout %26lt;%26lt; " X = " %26lt;%26lt; '\n';





int x;


cin%26gt;%26gt;x;


cout %26lt;%26lt; "n= " %26lt;%26lt; '\n';





int n;


cin%26gt;%26gt; n;





int ans = x^n;


cout %26lt;%26lt; "Answer: " %26lt;%26lt; ans %26lt;%26lt; '\n';





return 0;


}
Reply:std::{cout %26lt;%26lt; "n= " %26lt;%26lt; '\n'; //error is there i think..the {


std::cout %26lt;%26lt; "n= " %26lt;%26lt; '\n'; //change to this one





good luck
Reply:write cout%26lt;%26lt;"X="%26lt;%26lt;'\n';
Reply:cout%26lt;%26lt;"X="%26lt;%26lt;'\n';


No comments:

Post a Comment