Jump to content

Newbie :( Why wont my program work?

- - - - -

  • Please log in to reply
27 replies to this topic

#1
jim_jamaroo

jim_jamaroo

    Newbie

  • Members
  • PipPip
  • 20 posts
I've just written my fist program in C using an IDE called DEV-C, but when I click compile and run there are errors in my code.
I cant seem to work out what these errors are, can someone point them out to me? Any help/advice would be much appreciated :)
Attached you will find my C source file.
[ATTACH]3868[/ATTACH]

Attached Files

  • Attached File  Exe.c   1.53K   95 downloads


#2
prajmus

prajmus

    Newbie

  • Members
  • PipPip
  • 13 posts
You wrote maint instead of main at the beginning, that's the error.

Edited by ZekeDragon, 17 May 2011 - 03:45 PM.


#3
mebob

mebob

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 490 posts
Next time provide us with the errors, and the source code in your post, not as a download. Anyway, the issue is you have "main" spelled wrong. It should be "int main()" not "int maint()".

EDIT: Sorry prajmus, somehow I didn't notice you already posted the solution :confused:

Edited by mebob, 17 May 2011 - 06:25 PM.

Latinamne loqueris?

#4
Flying Dutchman

Flying Dutchman

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 889 posts
  • Location:::1
I'd point out that Dev-C++ IDE is outdated and no longer developed and you should consider finding another one. Code::Blocks works on Windows as well as Unix systems so you can have a consistent IDE if you like. If you're on Windows you can get Visual Studio Express edition, which is free, and has one of the best debuggers out there.
A conclusion is where you got tired of thinking.
#define class struct    // All is public.

#5
jim_jamaroo

jim_jamaroo

    Newbie

  • Members
  • PipPip
  • 20 posts

prajmus said:

You wrote maint instead of main at the beginning, that's the error.

cheers dude, it works fine now. If I want to find an error by myself in the future what is the best way of finding the problem.
DEV-C displayed the following error codes before I fixed the problem, what do they mean?

[Linker error] undefined reference to `WinMain@16'
ld returned 1 exit status

#6
jim_jamaroo

jim_jamaroo

    Newbie

  • Members
  • PipPip
  • 20 posts
Okay I shall provide you guys with the errors and source code in my post next time, thanks for the advice man :)

#7
jim_jamaroo

jim_jamaroo

    Newbie

  • Members
  • PipPip
  • 20 posts

Flying Dutchman said:

I'd point out that Dev-C++ IDE is outdated and no longer developed and you should consider finding another one. Code::Blocks works on Windows as well as Unix systems so you can have a consistent IDE if you like. If you're on Windows you can get Visual Studio Express edition, which is free, and has one of the best debuggers out there.

I'm doing an Electrical and Electronic Engineering degree and this programming task was part of my C programming course, so unfortunately I have to use the DEV-C++ IDE as my lecturer has specified that we use it :(
I'll defiantly download that Visual Studio Express edition for personal use, I've just bought a book called "The C Programming Language, second edition" I'm ganna work my way through all the programming exercises in that :)

#8
jim_jamaroo

jim_jamaroo

    Newbie

  • Members
  • PipPip
  • 20 posts
Thanks for all your help and advice :) I'm going to be writing 4 more basic C programs over the next week or so, I would be very grateful if you guys would help me out and give me some pointers . I'll post up my source codes and error messages if I get stuck again.
Thanks again dudes :D

#9
jim_jamaroo

jim_jamaroo

    Newbie

  • Members
  • PipPip
  • 20 posts
Okay guys, I've just completed my second ever C programming exercise, Dev-c is not displaying any error codes but the program doesn't work properly and I cant seem to work out what I've done wrong.
When I run the program I get an "0f" displayed rather than an integer, this is baffling me :s was wondering if guys could help me out again.
Below is my program description and source code...

Excise 2 description
First we illustrate the difference between int and double calculations. You will write a
program that takes two integers from the keyboard (as learnt in exercise 1). Then do
some arithmetic - divide the first number by the second number and then divide the
second by the first. Do both of these twice. The second time you do each you will
cast the numbers to doubles before the calculation. The result of each of these
calculations should be displayed to the screen.

Source code
#include<stdio.h> //supports stanrd input/output capabilities
#include<stdlib.h> //standard liberry of pre-programmed functions

/*Decalare variables*/
char inputstring[100];
int firstnumber;
int secondnumber;
int firstanswer;
int secondanswer;
double doublefirstanswer;
double doublesecondanswer;

int main() //main program
{
/*print title of program*/
printf("Exercise 2.1\n\n");

/*Get firstnumber from user and copy to firstname*/
printf("Please enter first number:"); //prompt user to input fist number
fgets(inputstring,sizeof(inputstring),stdin); //get integer from keyboard
sscanf(inputstring,"%d", &firstnumber); //copy integer to firstnumber

/*Get secondnumber from user and copy to second number*/
printf("Please enter second number:"); //prompt user to input second number
fgets(inputstring,sizeof(inputstring),stdin); //get integer from keyboard
sscanf(inputstring,"%d", &secondnumber); //copy integer to firstnumber

/*int calcluations*/
firstanswer = firstnumber / secondnumber; //define answer
secondanswer = secondnumber / firstnumber; //define secondanswer

/*double calculations*/
doublefirstanswer = ((double)firstnumber)/((double)secondnumber); //define doublefirstanswer
doublesecondanswer = ((double)secondnumber)/((double)firstnumber); //define doublesecondanswer

/*Display all of the answers to the screan*/
printf("\n\nUsing int, When %d is divided by %d, the answer is: %d\n",firstnumber, secondnumber, firstanswer); //print fisrt answer statment
printf("Using int, When %d is divided by %d, the answer is: %d",secondnumber, firstnumber, secondanswer); // print second answer statement
printf("\n\nUsing double, When %if is divided by %if, the answer is: %if\n",((double)firstnumber), ((double)secondnumber), doublefirstanswer); // print double first answer staement
printf("Using double, When %if is divided by %if, the answer is: %if",((double)secondnumber), ((double)firstnumber), doublesecondanswer); //print double second andswer statement

printf("\n\n");
system ("pause");
return 0;
}


Any help would be much appriciated :)

#10
prajmus

prajmus

    Newbie

  • Members
  • PipPip
  • 13 posts
Again not a big deal. To display double you should use %lf but you wrote %if so it expects int rather than double there. Change all i's to l's

#11
jim_jamaroo

jim_jamaroo

    Newbie

  • Members
  • PipPip
  • 20 posts

prajmus said:

Again not a big deal. To display double you should use %lf but you wrote %if so it expects int rather than double there. Change all i's to l's

cheers dude, cant believe i missed that! I think i need to brush uo my error checking skills.

#12
jim_jamaroo

jim_jamaroo

    Newbie

  • Members
  • PipPip
  • 20 posts

prajmus said:

Again not a big deal. To display double you should use %lf but you wrote %if so it expects int rather than double there. Change all i's to l's

xD lol cant believe i missed that! cheers dude :)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users