![]() |
| Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact |
| ||||||
This is a discussion on c help within the Everything Windows forums, part of the General PC Forums category; iv just started learning c and iv made this sorce file from scratch...dev-cpp comes up with: Code: Compiler: Default compiler ...
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 |
![]() |
iv just started learning c and iv made this sorce file from scratch...dev-cpp comes up with:
Code:
Compiler: Default compiler
Executing gcc.exe...
gcc.exe "C:\Dev-Cpp\Examples\Hello\Main.c" -o "C:\Dev-Cpp\Examples\Hello\Main.exe" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
C:\Dev-Cpp\Examples\Hello\Main.c:5: error: syntax error before "main"
C:\Dev-Cpp\Examples\Hello\Main.c:10: error: missing terminating " character
C:\Dev-Cpp\Examples\Hello\Main.c:11: error: syntax error before '(' token
C:\Dev-Cpp\Examples\Hello\Main.c:11: error: conflicting types for 'scanf'
C:\Dev-Cpp\Examples\Hello\Main.c:11: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
C:\Dev-Cpp\Examples\Hello\Main.c:11: error: conflicting types for 'scanf'
C:\Dev-Cpp\Examples\Hello\Main.c:11: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
C:\Dev-Cpp\Examples\Hello\Main.c:11: warning: data definition has no type or storage class
C:\Dev-Cpp\Examples\Hello\Main.c:12: error: missing terminating " character
C:\Dev-Cpp\Examples\Hello\Main.c:17: error: syntax error before '=' token
C:\Dev-Cpp\Examples\Hello\Main.c:21: error: syntax error before string constant
Execution terminated
Code:
#include <stdio.h>
int base,height,diagonal /* Base / 4 + Height = Diagonal*/
Main ()
{
/*Data input for User */
printf("enter base of triangle: ");
scanf("%d,&base);
printf("enter height of triangle: ");
scanf("%d,&height)
/* preform the conversion */
diagonal=(base/4)+height;
/*output results onto screen*/
printf("/nDiagonal of triangle = %ld",diagonal)
return o;
}
![]() oh btw, its an alternative way to work out the diagonal of a right angle triangle, although it isnt important. |
|
|
|
|
|
#2 |
![]() |
theres a number of mistakes there.
Code:
#include <stdio.h>
int base,height,diagonal; /* Base / 4 + Height = Diagonal*/
int main ()
{
/*Data input for User */
printf("enter base of triangle: ");
scanf("%i", base);
printf("enter height of triangle: ");
scanf("%i", height);
/* preform the conversion */
diagonal == (base/4)+height;
/*output results onto screen*/
printf("/nDiagonal of triangle = %i", diagonal);
return 0;
}
Not tested it though.
|
|
|
|
|
|
#3 | |
![]() ![]() Developer
|
Quote:
Code:
#include <stdio.h>
int base,height,diagonal; /* Base / 4 + Height = Diagonal*/
int main ()
{
/*Data input for User */
printf("enter base of triangle: ");
scanf("%i", base);
printf("enter height of triangle: ");
scanf("%i", height);
/* preform the conversion */
diagonal = (base/4)+height;
/*output results onto screen*/
printf("/nDiagonal of triangle = %i", diagonal);
return 0;
}
diagonal == (base/4)+height; should be diagonal = (base/4)+height; remeber that = means change the variable to, == means check if the variable is.
__________________
|
|
|
|
|
|
|
#4 |
![]() |
ok, thank you both... i should of remebered about the "=" bit...its what i just read about :P, can i ask why you changed the %d to %i? just wondered
![]() edit:compiled it with no errors (always a good thing), but after entering "base of triangle" and pressing enter, it says main.exe has encountered a problem, and needs to close....it may just be the compiler, because really it was intented for c++, or maybe its the source again?any help again would be appreciated thank you Last edited by willolner; 01-08-2007 at 01:43 AM.. |
|
|
|
|
|
#5 |
![]() ![]() Developer
|
I have no idea why he changed %d to %i, they are the same thing.
anyway, you need to pass a pointer or the address of a variable to scanf in order to modify it. (which is what were causing the error) to do this add & infront of the variable. also you used /n instead of \n in your last printf. ![]() working code, (I added getchar(); so that the window won't close immediatly) Code:
#include <stdio.h>
int base,height,diagonal; /* Base / 4 + Height = Diagonal*/
int main ()
{
/*Data input for User */
printf("enter base of triangle: ");
scanf("%i", &base);
printf("enter height of triangle: ");
scanf("%i", &height);
getchar();
/* preform the conversion */
diagonal = (base/4)+height;
/*output results onto screen*/
printf("\nDiagonal of triangle = %i", diagonal);
getchar();
return 0;
}
__________________
|
|
|
|
![]() |
| Thread Tools | |
|
|