-
11-03-06, 06:48 AM #1Registered Member
- Posts
- 1
Help on C programming with a program that converts Uganda shillings to foreign curren
Please assist me with this assignment, am new to C programming
A C program that can convert Uganda shillings to dollars, rands, euros, and pound sterlings when entering the Uganda Shillings at the key board
1 dollar=1850 shillings, 1 euro=2880 shillings, 1 pound sterling = 3280 shillings, 1 Rand = 200 shillings
This what I have tried but it has 1 error that there is a mising statement.
*A program that uses functions to convert currency valves enter from the
keyboard in Ug_shillings into foreign currency*/
#include<stdio.h>
#include<conio.h>
float US_dollars,SA_rands,euros,pound_sterlings;
float US_dollar=1850;
float SA_rand=200;
float euro=2280;
float pound_sterling=3390;
int Ug_shillings;
float answer;
main()
{
/*Input amount in Ug_shillings to be converted*/
printf("input amount to be coverted in Ug_shillings\n:");
scanf("%d",&Ug_shillings);
/*Convert amount in Ug-shinnings to dollars*/
US_dollar=1850
US_dollars=Ug_shillings/1850
{
printf("%d/%d=%f\n",Ug_shillings,US_dollar,US_dollars);
Answer=float US_dollars(US_dollars);
}
/*Convert amount in Ug-shilling to SA_rands*/
SA_rand=200
SA_rands=Ug_shillings/200
{
printf("%d/%d=%f\n",Ug_shillings,SA_rand,SA_rands);
answer=float SA_rands(SA_rands);
}
/*Convert amount in Ug_shillings to euro*/
euro=2280
euros=Ug_shillings/2280
{
Printf("%d/%d=%f\n",Ug_shillings,euro,euros)
answer=float euros(euros);
}
/*Convert amount in Ug_shillings to pound_sterlings*/
pound_sterling=3390
pound_sterlings=Ug_shillings/3390
{
printf("%d/%d=%f\n",Ug_shillings,pound_sterling,pound_sterlin gs);
answer=float pound_sterlings(pound_sterlings);
}
getch();
return 0;
}Last edited by jdibya; 11-03-06 at 06:54 AM. Reason: The program has #include<stdio> and #include<conio> but they do not appear
-
11-03-06, 11:13 AM #2
The error "statement missing" indicates that you've left out a semicolon ( ; ) somewhere, as you have done in nine places in this case...
{
/*Input amount in Ug_shillings to be converted*/
printf("input amount to be coverted in Ug_shillings\n:");
scanf("%d",&Ug_shillings);
/*Convert amount in Ug-shinnings to dollars*/
US_dollar=1850; /***** HERE *****/
US_dollars=Ug_shillings/1850; /***** HERE *****/
{
printf("%d/%d=%f\n",Ug_shillings,US_dollar,US_dollars);
Answer=float US_dollars(US_dollars);
}
/*Convert amount in Ug-shilling to SA_rands*/
SA_rand=200; /***** HERE *****/
SA_rands=Ug_shillings/200; /***** HERE *****/
{
printf("%d/%d=%f\n",Ug_shillings,SA_rand,SA_rands);
answer=float SA_rands(SA_rands);
}
/*Convert amount in Ug_shillings to euro*/
euro=2280; /***** HERE *****/
euros=Ug_shillings/2280; /***** HERE *****/
{
Printf("%d/%d=%f\n",Ug_shillings,euro,euros); /***** HERE *****/
answer=float euros(euros);
}
/*Convert amount in Ug_shillings to pound_sterlings*/
pound_sterling=3390; /***** HERE *****/
pound_sterlings=Ug_shillings/3390; /***** HERE *****/
{
printf("%d/%d=%f\n",Ug_shillings,pound_sterling,pound_sterlin gs);
answer=float pound_sterlings(pound_sterlings);
}
getch();
return 0;
}
-
11-03-06, 12:14 PM #3
-
11-03-06, 12:19 PM #4
-
11-03-06, 12:24 PM #5Code:
cout << "will do your homework for free, only 12.99$ an hour";
-
11-03-06, 12:31 PM #6
I can't understand your program, and it's easier to write another one, so...
<Font face= "ms sans serif">
#include <stdio.h>
#include <conio.h>
void main()
{
float UG_Shillings, US_Dollars, SA_Rands, Euros, Pound_Sterlings;
clrscr();
printf("Enter the amount in Uganda Shillings: ");
scanf("%f",&UG_Shillings);
US_Dollars=UG_Shillings/1850;
SA_Rands=UG_Shillings/200;
Euros=UG_Shillings/2280;
Pound_Sterlings=UG_Shillings/3390;
printf("\nValue in Dollars: %6.2f",US_Dollars);
printf("\nValue in Rands: %6.2f",SA_Rands);
printf("\nValue in US Euros: %6.2f",Euros);
printf("\nValue in US Pounds Sterlings: %6.2f",Pound_Sterlings);
getch();
}
</Font>
-
11-03-06, 12:32 PM #7
-
11-03-06, 12:33 PM #8squishy
- Posts
- 2,754
Exactly what are you trying to do here:
?Answer=float US_dollars(US_dollars);
If "float US_dollars(US_dollars)" is a legal expression in C, I've never seen it before.
Also:
C is case sensitive - "Printf" is not the same as "printf", and:Answer=float US_dollars(US_dollars);
Printf("%d/%d=%f\n",Ug_shillings,euro,euros);
"US_dollar" isn't an integer.printf("%d/%d=%f\n",Ug_shillings,US_dollar,US_dollars);
Lastly, there's this:
It's perfectly legal C (provided you don't forget the semicolon), but it won't get you the result you're probably expecting. Since Ug_shillings is an int, the result of the division will be truncated. You can fix this by using a floating point constant instead of an integer in the expression (ie. use "1850.0" instead of "1850", or just use the variable "US_dollar").US_dollars=Ug_shillings/1850;



Bookmarks