Calling a character in c

I am trying to call a character into my code so that I can show it as a declaration before it goes into a calculation. I am not sure how to do this. What I am trying to do is make a simple currency converter. Please see below my code I have included as much information as I can.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  #include <stdio.h>
#include <math.h>
int main()
{
	char n1[20];// rand
	char n2[20];// pounds
	char n3[20];// yen
	char Rand = 10.3;

puts("What currency do you want to convert to US$:\n");
scanf("%s",n1,n2,n3);
printf("\n");
printf("You want to convert %s to US$\n",n1,n2,n3);
printf("\n");
printf("%s to US$= ifRand\n"); // calls the rate of exchange.
return(0);
}
Hi piczim,

Have a read of these - especially the examples:

http://www.cplusplus.com/reference/cstdio/scanf/
http://www.cplusplus.com/reference/cstdio/printf/
http://www.cplusplus.com/reference/cstdio/puts/


Note that they all have return values - make use of them to see whether the function call worked. Using a switch is a clever way to deal with this.

Note that the format string in these functions has to match the number of variables specified, so line 11 might be (providing there are spaces in the input):

scanf("%s %s %s",&n1,&n2,&n3);

You can use scanf to read in a double type rather than try to deal with strings - read the documentation.

Also read up about data types:

http://www.cplusplus.com/doc/tutorial/


A char is a single character, so line 8 makes no sense.

Hope all goes well.

EDIT:

Have a read of this as well - it may help yo quite a lot.

http://zanasi.chem.unisa.it/download/C.pdf
Last edited on
Topic archived. No new replies allowed.