QJ.NET | Videos | Forums | iPhone | MMORPG | Nintendo DS | Wii | PlayStation 3 | PSP | Xbox 360 | PC | Downloads | Contact Us
Forums | Gaming News | Videos | Downloads | Today's Posts | Mark Forums Read | Chat | FAQ | Members List | Contact

QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides

Go Back   QJ.net Game Discussion - PSP, Xbox, Wii, PS3, PSP Homebrew, and PSP Guides > Consumer > General PC Forums > Everything Windows
The above video goes away if you are a member and logged in, so log in now!

c help

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 ...

Reply
 
LinkBack Thread Tools
Old 01-07-2007, 03:53 PM   #1
 
willolner's Avatar
 
Join Date: Jul 2006
Posts: 137
Trader Feedback: 0
Smile c help

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
heres the sorce
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;
}
thanks for any help

oh btw, its an alternative way to work out the diagonal of a right angle triangle, although it isnt important.
willolner is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-07-2007, 04:29 PM   #2
 
will1234's Avatar
 
Join Date: Oct 2005
Real First Name: Will
Location: Sheffield, UK
Posts: 844
Trader Feedback: 0
Default

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;
}
Should work Not tested it though.
will1234 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-07-2007, 04:46 PM   #3

Developer
 
Waterbottle's Avatar
 
Join Date: Feb 2006
Location: Norway
Posts: 382
Trader Feedback: 0
Default

Quote:
Originally Posted by will1234
theres a number of mistakes there.
Should work Not tested it though.
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;
}
one more error,

diagonal == (base/4)+height;
should be
diagonal = (base/4)+height;

remeber that = means change the variable to, == means check if the variable is.
__________________

Waterbottle is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-08-2007, 01:28 AM   #4
 
willolner's Avatar
 
Join Date: Jul 2006
Posts: 137
Trader Feedback: 0
Default

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..
willolner is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-08-2007, 01:56 PM   #5

Developer
 
Waterbottle's Avatar
 
Join Date: Feb 2006
Location: Norway
Posts: 382
Trader Feedback: 0
Default

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;
}
__________________

Waterbottle is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-08-2007, 02:13 PM   #6
 
willolner's Avatar
 
Join Date: Jul 2006
Posts: 137
Trader Feedback: 0
Default

Thanks man, i really appreciate the help and th tips

thanks agen
willolner is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -8. The time now is 05:29 PM.



Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY
Copyright © 2009, QJ.NET. All Rights Reserved.
Contact Us