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 :)