Hello everyone! This is my 1st post here, in fact I just stumbled across these forums as I attempted to solve a problem I have come across. I am a novice programmer trying to teach myself C using IvorHorton's Beginning C 3rd ed.
I'm only at the end of chapter 3 and although I've been enjoying things I'm stumped. One of the exercises in Chapter 3 is to write a simple fahrenheit to celsius converter program. I made what I though was a pretty good fist of it but I can't get it to compile using either Visual C++.Net 2003 or Dev C++. Interestingly, both compilers seem to be complaining not necessarily about my code, but about some lines in the #included stdio header file.
Specifically, VC++ reports error C2059: syntax error : 'type' and the offending line it flags up in stdio.h is:
"typedef _W64 unsigned int size_t;"
Does this have anything to do with the fact that my PC is an Athlon64? Is there perhaps updated header fils I should download, or is my code just borked?
Anyway, here's my source code:
Code:
/**************************************
* *
* Solution to Exercise 3.1, page 140 *
* Temperature converter program *
* By Steven MacDiarmid. 16/2/05 *
* *
************************************/*
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int choice;
double temp = 0.0, fahr = 0.0, celsius = 0.0;
printf("\n*******************************************************");
printf("\nTemperature Converter\n");
printf("\n(C) 2005 SGM Systems");
printf("\n\n1. Convert temperature from degrees Celsius to Fahrenheit.");
printf("\n2. Convert temperature from degrees Fahenheit to Celsius.");
scanf("%d", &choice);
switch(choice)
{
case 1:
printf("\n\nPlease enter a temperature in Celsius: ");
scanf("%lf", temp);
fahr = temp * 1.8 + 32.0;
printf("\n\n%lf degrees F = %lf degrees C", temp, celsius);
break;
case 2:
printf("\n\nPlease enter a temperature in Fahrenheit: ");
scanf("%lf", temp);
celsius = (temp - 32.0) * 5.0 / 9.0;
printf("\n\n%lf degrees C = %lf degrees F", temp, fahr);
break;
default:
printf("\n\nInvalid selection, enter 1 or 2.");
break;
}
system("pause");
return 0;
}
I'm sure it's a pretty ham-fisted attempt but given my limited knowledge I think this should compile. If anyone can spot something amiss I'd be very grateful.
Many thanks, Steve