コード例 #1
0
main(){
	int choice;//variable for choice
		while((choice = menu()) != 5)
		{
			switch(choice)
			{
			case 1:;
					int num;
					printf("Enter Number: ");//asks the user to enter the number that will be converted to words
					scanf("%d",&num);
					printf("%s\n",numToWords(num));//prints the number in words
					
					break;
			case 2:;
					char word[256];
					printf("Enter Word: ");//asks the user the phrase that will be converted to numbers
					getchar();
					fgets(word,256,stdin);
					trim(word);
					printf("%d\n",wordsToNum(word));//prints the phrase in numbers
					break;
			case 3:	
					;
					char word2[256];
					char currency[256];
					printf("Enter Word: ");//asks the user the phrase that will be converted to numbers
					getchar();
					fgets(word2,256,stdin);
					trim(word2);
					printf("Enter Currency: ");//asks the user for the currency
					fgets(currency,256,stdin);
					trim(currency);
					printf("%s\n",wordsToCurrency(word2,currency));//prints the currency followed by the numbers
					break;
			case 4:;
					char number[256];
					printf("Number from 0 to 1,000,000\n");//asks the user for the number
					printf("Number: ");
					scanf("%s",number);
					
					printf("Enter Character: ");//asks the user for the character
					char character;
					getchar();
					scanf("%c",&character);
					
					int jumps;
					printf("Enter Jumps: ");
					scanf("%d", &jumps);//asks the user for the jumps
					
					printf("%s\n",numberDelimited(number,character,jumps));//prints the number jumped by characters
					break;
			}
		}

}
コード例 #2
0
int main(){
  int choice, num, jmp;
  char del;
  char str[100];
  do{
    mainMenu(&choice);
    switch(choice){
      case 1: // numbers to words
        printf("\nEnter a 6-digit number:\n");
        scanf("%d", &num);
        numToWords(num);
        printf("\n\n");
        break;
      case 2: // words to numbers
        printf("\nEnter a 6-digit number in words:\n");
        getchar();
        gets(str);
        wordsToNum(str);
        printf("\n\n");
        break;
      case 3: //words to currency
        break;
      case 4: // number delimited
        printf("\nEnter a 6-digit number:\n");
        scanf("%d", &num);
        getchar();
        printf("\nEnter a character:\n");
        scanf("%c", &del);
        getchar();
        printf("\nEnter number of jumps:\n");
        scanf("%d", &jmp);
        numberDelimited(num, del, jmp);
        break;
      case 0: // exit
        printf("\nExit.\n\n");
        break;
      default: printf("Invalid choice. Try again.\n");
    }
  }while(choice!=0);

  return 0;
}