Help with hmwrk

0 Mookol Dookol · June 13, 2015
i need help with functions ASAP i have an assignment due soon.



#include 
#include

    //peramaters for function

    void randomNumber (int x);
    void randomNumber2(int x);

    int main() {

    float money;

    int number, a = randomNumber, b, c, d;



    scanf("%d",&number);
    a=   number % 10000  /1000;
    b=   number % 1000  /100;
    c=   number % 100  /10;
    d=   number % 10  /1;



    printf("Welcome to the IPC144 Cheque Generator...\n");
    printf("\nEnter a monetary value from $0.01 to $9999.99 inclusive: ");

    scanf("%f",&money);

    if (money < 0.01 || money > 9999.99){
    printf("Sorry, cannot create cheque for that amount, try again next time!\n");
    }

    else if(money > 0.01){
    printf("PAY TO THE ORDER OF... bsmith (%.2f)\n", money);
    }


   return 0;
}


        void randomNumber (int x) {  //deffinition for function
     //printing 4 digits
        if(x == 0){
       printf("Zero");}
        else if(x == 1){
        printf("One");}
        else if(x == 2){
       printf("Two");}
        else if(x == 3){
       printf("Four");}
        else if(x == 5){
       printf("Five");}
        else if(x == 6){
       printf("Six");}
        else if(x == 7){
       printf("Seven");}
        else if(x == 8){
       printf("Eight");}
        else if(x == 9){
       printf("Nine");}
               }


        void randomNumber2 (int x) {
        if(x == 11){
        printf("Eleven");}
        else if(x == 12){
       printf("Twelve");}
        else if(x == 13){
       printf("Thirteen");}
        else if(x == 14){
       printf("fourteen");}
        else if(x == 15){
       printf("Fifteen");}
        else if(x == 16){
       printf("Sixteen");}
        else if(x == 17){
       printf("Nine");}
        else if(x == 18){
       printf("Nine");}
        else if(x == 19){
       printf("Nineteen");}

        else if(x == 20){
       printf("Twenty");}
        else if(x == 30){
       printf("Thirty");}
        else if(x == 40){
       printf("Fourty");}
        else if(x == 50){
       printf("Fifty");}
        else if(x == 60){
       printf("Sixty");}
        else if(x == 70){
       printf("Seventy");}
        else if(x == 80){
       printf("Eighty");}
        else if(x == 90){
       printf("Ninety");}
        else if(x == 0){
       printf("Zero");}


            }



this is my code

Post a Reply

Replies

Oldest  Newest  Rating
0 IneptFish d · June 14, 2015
For those endless else if statements, cant you use a Switch method?

I don't know, to be honest, because I speak Java only.
0 K D · June 14, 2015
yes he could use a switch. 

Why do you have two functions for?  why not combine them?  And what are you trying to do here "a = randomNumber".  If you are trying to set the variable equal to the return value of a function call you are forgetting the parameters as well as the fact that its a function with a return type of void which means it won't work.  If you are trying to set it to the same value as another variable well you forgot to declare and initialize that variable.

also what is the point of these variables:
    a = randomNumber, b, c, d;

and these lines of code:
    scanf("%d",&number);
    a=   number % 10000  /1000;
    b=   number % 1000  /100;
    c=   number % 100  /10;
    d=   number % 10  /1;
you don't tell the user anything about what to enter and you never print them out or even use those variables any where else...
I am asking these questions because i don't understand what your program is supposed to do...  I would really like to help :)...

 i am truly sorry if I come off blunt and/or rude I really don't mean to...
0 Alan Johnson · June 14, 2015
What exactly is your assignment and what do you need help with?
  • 1

C

107,018 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator