Click here to Skip to main content
15,895,817 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
#include<stdio.h>

void main()
{
     int length, weight, c;

     printf("\n Plz input length: ");
     printf("\n Plz input weighth: ");
     scanf("%d", &length);
     scanf("%d", &weight);

     c = (length + weight)/ 2;

     prinf("\n perimeter: %d", c);
}


Sry im new to C just got the lession in school the yes-yesterday so here can i ask what did i wrong in the code above it keep saying error to Scanf so instead of 1 scanf i switch to 2 XD! and priftf too... ~.~ Hope to have someone help :(
Posted
Updated 8-Sep-12 14:58pm
v4
Comments
[no name] 8-Sep-12 21:00pm    
What is the exact error message? Does it have anything to do with the 2 different spellings of length? length and lenghth
enhzflep 8-Sep-12 21:20pm    
Content removed, inserted verbatim into an Answer.
pasztorpisti 8-Sep-12 21:32pm    
+5, This should be an answer. As an addition I would mention that the cause of a '{' error can be that some compilers want to see a newline at the end of your source file.
enhzflep 8-Sep-12 21:42pm    
Sounds good to me. :)
Thanks for the tip re: some crappy compilers

1 solution

Apart from the missing 't' in the 2nd last line, there's no reason for this not to compile. That said, not really sure what it is you're trying to calculate here - I guess you're just getting the hang of the language, and playing around.

Given the use of the words length and perimeter & the /2 in the final calc, I've altered it slightly so that it calculates the perimeter of a rectangle (or square)

I also separated the printf/scanf pairs so that it's easier and more intuitive to use. Enjoy :)


C++
#include <stdio.h>

int main()
{
     int length, width, perim;

     printf("Plz input length: ");
     scanf("%d", &length);

     printf("\n Plz input width: ");
     scanf("%d", &width);

     perim = (length + width) * 2;
     printf("\n perimeter: %d", perim);

     return 0;
}
 
Share this answer
 
Comments
pasztorpisti 9-Sep-12 3:30am    
+5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900