Hi all.. If i knew this website existed it would have saved me hours of useless

Discussion in 'C++' started by noob_dave, Aug 9, 2007.

  1. noob_dave

    noob_dave New Member

    Joined:
    Aug 9, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Hi all.. If i knew this website existed it would have saved me hours of useless research!!

    Hi im David... first year programming.

    I was making this code and I keep getting the error

    "c:\documents and settings\david\my documents\pp2\real\real\real.cpp(26) : error C2143: syntax error : missing ';' before ')'"

    ........................................

    This is the program I have made, the error is on like 26 but I don't know the reason for the error.

    Maby pros like you could help :)

    Code:
    #include "stdafx.h"
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    
    	float n1, n2, hn, ln; //Defining variables LINE 10
    
    	printf("Insert first number = ");
    	scanf("%f", &n1);
    
    	printf("Insert second number = ");
    	scanf("%f", &n2);
    
    	 if ( n1 > n2 ){
          hn = n1;
          ln = n2;  // LINE 20
       } else {        
          hn = n2;
          ln = n1;
            }
    
    	 for (ln < hn; ln++)
    	 {
    	String formats = "%i  %f  %f\n";
    	StdOut.printf(ln, ln * ln, ln * ln * ln);
    	 }             //LINE 30
    
    	system("pause");
    
    	return 0;
    }
     
    Last edited by a moderator: Aug 9, 2007
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    The error is
    Code:
    for (ln < hn; ln++)
    and it should be
    Code:
    for (;ln < hn; ln++)
    but I see that you dont have ln initialized and so it should be something like
    Code:
    for (ln=0;ln < hn; ln++)
     
  3. noob_dave

    noob_dave New Member

    Joined:
    Aug 9, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    I tried that before in my original program and the same error appeared, I seriously don't know how it keeps failing...

    Lol, I asked my brother who also did programming and he was also puzzled on how it doesn't work.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    You probably need to be working on "Hello World" program because I see you have written even the printf statement incorrect.
     
  5. noob_dave

    noob_dave New Member

    Joined:
    Aug 9, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    this is a new sem for me...

    last sem we were using the cin, cout approach...

    i just converted it into scanf() and printf()...

    thx, ill go through my work again and see how it is...
     
  6. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    Scanf and printf are C functions. One can use them in C++, but writing C as C++ is a fool's mission. Don't bother. Anyone doing woodworking can measure with their forearm, mark with chalk, and cut with an axe. Anyone else may ask, "Why the hell would you do that? Masochisitic tendendies?"
     
  7. seeguna

    seeguna New Member

    Joined:
    Jun 20, 2007
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Technical Consultant
    Location:
    Chennai
    Code:
    for (ln < hn; ln++)
    	 {
    	String formats = "%i  %f  %f\n";
    	StdOut.printf(ln, ln * ln, ln * ln * ln);
    	 }             //LINE 30
    Replace the above coding with the followed one ,u will get answer
    Code:
     for (;ln < hn; ln++)
    	 {
    	printf(" %f %f %f\n",ln, ln * ln, ln * ln * ln);
    	 }             //LINE 30
     
    Last edited by a moderator: Aug 10, 2007
  8. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    [COMMENT]seeguna, Please use code block when you have code snippets in the posts.[/COMMENT]
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice