Sunday, August 2, 2009

Whats wrong with this C++ program?

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





int main()


{


char start, end, dummy;


int cnt, line;





printf("Enter Start Character");


start = getchar();


dummy = getchar();





printf("Enter End Character");


end = getchar();





for(line = 0;cnt = start; cnt%26lt;=end; cnt++; line++);


{


printf("%3d%3x%2c", cnt, cnt, cnt);


if(line%3==0 line!=0)%26amp;%26amp;


{printf("\n")


}





return 0;


}














this is just the start but it says i have errors on line 15 and 18 and i dont know what they are...








a little help would be greatly appreciated.

Whats wrong with this C++ program?
List of problems:





Your for statement is wrong. You can only have 3 separate statements. It should be like this to correct the syntax (commas are okay as dividers):


for ( line=0 , cnt = start; cnt%26lt;=end; cnt++, line++)





You are missing a '}' after your if statement, you close the for loop but not the if statement.





The if statement doesn't have the %26amp;%26amp; (and) sign at the correct spot. It should be : if ( line%3 == 0 %26amp;%26amp; line != 0 )





You are missing the ';' after the printf statement. This will work below:














int main()


{


char start, end, dummy;


int cnt, line;





printf("Enter Start Character");


start = getchar();


dummy = getchar();





printf("Enter End Character");


end = getchar();





for(line = 0, cnt = start; cnt%26lt;=end; cnt++, line++);


{


printf("%3d%3x%2c", cnt, cnt, cnt);





if(line%3==0 %26amp;%26amp; line!=0)


printf("\n");


}





return 0;


}
Reply:Well, first of all you only got a C++. Next time try shooting for at least a B-...
Reply:on line 15 {printf("\n") it should be printf("\n");


Check your block code openers and closers, you got more { than you do }.

calling cards

No comments:

Post a Comment