Code: #include <stdio.h> #include <stdlib.h> #include <string.h> /* Quality of Capital Calculator */ int main() {/* Gold Price (Debt indicator)*/ /*Currency Conversion*/ float USD=1; float EU=73 * 0.01; /*Euro*/ float AUD=97 * 0.01; /*Australian Dollar*/ float BRZ=1757 * 0.01; /*Brazilian Real*/ float CAN=101 * 0.01; /* Canadian Dollar */ float CNY=635 * 0.01; /*Chineses Yuan*/ float HKD=777 * 0.01; /*Hong Kong Dollar*/ float INR=4928 * 0.01; /* Indian Rupee*/ float BP=62 * 0.01; /*British Pound*/ float RUB=3092 * 0.01; /*Russian Ruble*/ float CHF=89 * 0.01; /*Swiss Franc*/ /*User Input */ /*User Selection*/ char USD1 [3]=("USD"); char usd [3]=("usd"); char EU1 [3]=("EU"); char eu [3]=("eu"); char AUD1 [3]=("AUD"); char aud [3]=("aud"); char BRZ1 [3]=("BRZ"); char brz [3]=("brz"); char CAN1[3]=("CAN"); char can[3]=("can"); char CNY1[3]=("CNY"); char cny[3]=("cny"); char HKD1[3]=("HKD"); char hkd[3]=("hkd"); char INR1[3]=("INR"); char inr[3]=("inr"); char BP1[2]=("BP"); char bp[2]=("bp"); char RUB1[3]=("RUB"); char rub[3]=("rub"); char CHF1[3]=("CHF"); char chf[3]=("chf"); char gold [10]; /* used to convert curr and hkd into number values using strcmp */ float input1; float input2; float input3; float input4; float input5; float input6; float input7; float input8; float input9; float input10; float input11; float input12; float input13; float input14; float input15; float input16; float input17; float input18; float input19; float input20; float input21; float input22; /*storage for gold price and default currency*/ float gold1; float curr1; /* currency value for converting to gold */ char curr [10]; /*Currency Input*/ printf("Please enter one of the following currencies: USD, EU, AUD, BRZ (Brazilian Real), CAN (Canadian Dollar), CNY (Yuan), HKD (Hong Kong Dollar, INR (Indian Rupee), BP (British Pound, RUB (Russian Ruble),or CHF (Swiss Franc.\n"); gets(curr); /*input check*/ input1=strcmp(curr,hkd); if (input1=='0') { printf("Hello Test HK.\n"); curr1=HKD; }; input2=strcmp(curr,HKD1); if (input2=='0') { printf("Hello Test HK.\n"); curr1=HKD; }; input3=strcmp(curr,BP1); if (input3=='0') { printf("Hello Test BP.\n"); curr1=BP; }; input4=strcmp(curr,bp); if (input4=='0') { printf("Hello Test BP.\n"); curr1=BP; }; input5=strcmp(curr,EU1); if (input5=='0') { printf("Hello Test EU.\n"); curr1=EU; }; input6=strcmp(curr,eu); if (input6=='0') { printf("Hello Test EU.\n"); curr1=EU; }; input7=strcmp(curr,RUB1); if (input7=='0') { printf("Hello Test RUB.\n"); curr1=RUB; }; input8=strcmp(curr,rub); if (input8=='0') { printf("Hello Test rub.\n"); curr1=RUB; }; input9=strcmp(curr,AUD1); if (input9=='0') { printf("Hello Test AUD.\n"); curr1=AUD; }; input10=strcmp(curr,aud); if (input10=='0') { printf("Hello Test AUD.\n"); curr1=AUD; }; input11=strcmp(curr,INR1); if (input11=='0') { printf("Hello Test INR.\n"); curr1=INR; }; input12=strcmp(curr,inr); if (input12=='0') { printf("Hello Test INR.\n"); curr1=INR; }; input13=strcmp(curr,BRZ1); if (input13=='0') { printf("Hello Test BRZ.\n"); curr1=BRZ; }; input14=strcmp(curr,brz); if (input14=='0') { printf("Hello Test Brz.\n"); curr1=BRZ; }; input15=strcmp(curr,CAN1); if (input15=='0') { printf("Hello Test CAN.\n"); curr1=CAN; }; input16=strcmp(curr,can); if (input16=='0') { printf("Hello Test CAN.\n"); curr1=CAN; }; input17=strcmp(curr,CNY1); if (input17=='0') { printf("Hello Test CNY.\n"); curr1=CNY; }; input18=strcmp(curr,cny); if (input18=='0') { printf("Hello Test CNY.\n"); curr1=CNY; }; input19=strcmp(curr,CHF1); if (input19=='0') { printf("Hello Test CHF.\n"); curr1=CHF; }; input20=strcmp(curr,chf); if (input20=='0') { printf("Hello Test CHF.\n"); curr1=CHF; }; input21=strcmp(curr,USD1); if (input21=='0') { printf("Hello Test USD.\n"); curr1=USD; }; input22=strcmp(curr,usd); if (input22=='0') { printf("Hello Test USD.\n"); curr1=USD; }; printf("The conversion rate is: %f .\n" ,curr1); return (0); }; Hi. I have been trying to work on his one part of a program of mine, and up to this point it has gone pretty well. But every time I have tried to run this program, I get a #QNANO error. I made sure all my variables for the currencies were floats, but it still is not working. What is wrong with this. I have rechecked everything and everything seems ok. Thanks
Ugh! Your coding style still needs more work in terms of readability, organization, and indention. Anyways, you need to change all your "input#" variables to int type. That's because the "strcmp" function returns an integer value. Second, for your "if" statements: Code: if (input1=='0') There is no need to have single quotes around the 0. That's because your input variable is an integer type. Get rid of the single quotes. Code: if (input1==0) Third, regarding strings: Code: char USD1 [3]=("USD"); Ditch the parenthesis, and get rid of the size value inside the square brackets. You should have all your string variables (that are set equal to a string) like this: Code: char USD1 []="USD"; Follow my instructions, and your program should run without any runtime errors.
Thanks ! I am sorry for writing it crappy, but I am still a novice with C (just finished a book on it) and I am trying to implement it. Anyways, in regards to to you first comment, what could improve in regards to my programming style? Does the input series (input1, input2) have anything to do with my code not being the most organized? Are there any books you recommend? I see the biggest problems with my code, and how I got there. I put parenthesis around the char is on account of getting used to atoi and I kind of forgot I did not need to with char. The other thing is that, with the if statement, is that I was using those single quotes on single characters, and kind of got into a little mental loop. I appreciate your time. Post Merge: [time]1321110142[/time] Oh, and by the way it works!
Your if statements just need to have the brackets aligned properly, and have a space in between, like this: Code: input1=strcmp(curr,hkd); if (input1=='0') { printf("Hello Test HK.\n"); curr1=HKD; }; input2=strcmp(curr,HKD1); if (input2=='0') { printf("Hello Test HK.\n"); curr1=HKD; }; input3=strcmp(curr,BP1); Group the relevant lines of code to each other, just like how the input#=strcmp(curr,<string>); go together with the if statement that checks it.