Hello, this is my first post, so I hope I don't come across negatively. I just started learning C programming language last week, so I am a complete newbie. I used to write basic scripts on mIRC about 8-10 years back, so i have a basic idea of what's going on. very basic...
I started watching these University lectures here and the students were given an assignment to take input from the user and output how a viking would say that number. Well, I figured I would try the same thing and here it is. I am traveling in Vietnam right now, so I thought it would be a good idea to just use vietnamese instead of viking.
The program is far from incomplete but I would like help on only one part for now. The If statement near the end is not working properly. When the program gets to that part, the variable is valid_entry is 1 and not 0, but it continues with the code as if it were 0. Thanks for your time and sorry i typed so much!
Code:#include <stdio.h> int main(void) { int number_input; //input from user. int greater_than_ten = 0; //avoids duplicate names. int valid_entry = 0; //checks that the input is valid int complete = 0; //will cause the program to loop //char proceed_again = 'n'; //will allow to repeat translation. printf("Vietnamese Number Translator.\n\n"); printf("Type a number from 1-100. "); scanf("%d", &number_input); while ("complete == 0") { //check to make sure the number is between 1-100 if (number_input < 101 && number_input > 0) { valid_entry = 1; //skips the error complete = 1; //completes the translation printf("\n"); printf("In Vietnamese, we say \""); //this section will calculate the numbers. //it will group the 10's place with the one's. //number 100 if (number_input == 100) printf("mot tram\".\n"); //for numbers 11-19 if (number_input >10 && number_input <20) { printf("muoi"); number_input = number_input - 10; } //for number 20 if (number_input == 20) { printf("hai muoi"); number_input = number_input - 10; greater_than_ten = 1; } //for numbers 21-30 if (number_input >20 && number_input <31) { printf("hai muoi"); number_input = number_input - 20; greater_than_ten = 1; } //for numbers 31-40 if (number_input >30 && number_input <41) { printf("ba muoi"); number_input = number_input - 30; greater_than_ten = 1; } //for numbers 41-50 if (number_input >40 && number_input <51) { printf("bon muoi"); number_input = number_input - 40; greater_than_ten = 1; } //for numbers 51-60 if (number_input >50 && number_input <61) { printf("lam muoi"); number_input = number_input - 50; greater_than_ten = 1; } //for numbers 61-70 if (number_input >60 && number_input <71) { printf("sau muoi"); number_input = number_input - 60; greater_than_ten = 1; } //for numbers 71-80 if (number_input >70 && number_input <81) { printf("bay muoi"); number_input = number_input - 70; greater_than_ten = 1; } //for numbers 81-90 if (number_input >80 && number_input <91) { printf("tam muoi"); number_input = number_input - 80; greater_than_ten = 1; } //for numbers 91-99 if (number_input >90 && number_input <100) { printf("chin muoi"); number_input = number_input - 90; greater_than_ten = 1; } //combines with previous section if needed. if (number_input == 1) printf(" mot\"."); if (number_input == 2) printf(" hai\"."); if (number_input == 3) printf(" ba\"."); if (number_input == 4) printf(" bon\"."); if (number_input == 5) printf(" lam\"."); if (number_input == 6) printf(" sau\"."); if (number_input == 7) printf(" bay\"."); if (number_input == 8) printf(" tam\"."); if (number_input == 9) printf(" chin\"."); if (number_input == 10 && greater_than_ten == 0) //to avoid * muoi muoi for printf("muoi\"."); //numbers ending in 0. if (number_input == 10 && greater_than_ten == 1) //needed to place a "."" at the printf(".\""); //end of numbers ending in 0. printf("\n"); //will print a new line } if ("valid_entry == 0") { //added just to test the values printf("v = %d c = %d n = %d", valid_entry, complete, number_input); // printf("Sorry, please choose a number between 1-100. "); scanf("%d", &number_input); } } return 0; }



