My Final Project

Write your question here.
I am struggling with my code, it abends when it is trying to read the two numbers as input. It appears to loop and then gives me an option BREAK. Here are the guidelines:
Create a text-based, menu-driven program that allows the user to choose whether to add, subtract, multiply or divide two numbers. The program should then input two double values from the user, perform the appropriate calculation, and display the result. Use an array of function pointers in which each pointer represents a function that returns void and receives two double parameters.

Any help would be very much appreciated!

[code]
Put the code you need help with here.
include <stdio.h>
int main()
{
void addition(double number1, double number2); /* create the functions */
void subtraction(double number1, double number2);
void division(double number1, double number2);
void multiplication(double number1, double number2);
int inputfunc=1;
double inputnum1=0;
double inputnum2=0;

while (inputfunc >= 1 && inputfunc <= 4) /* If function to be performed are those below then continue performing loop */
{
printf("Press 1 to add two numbers.\n");
printf("Press 2 to subtract two numbers.\n");
printf("Press 3 to multiply two numbers.\n");
printf("Press 4 to divide two numbers.\n");
printf("Press 5 to exit.\n");
printf("Enter your choice\n");
scanf_s("%d",&inputfunc);

if( inputfunc == 5) /* Exit program if requested via 5 function */
return(0);

printf("Enter both numbers with a space in between.");
scanf_s("%lf %lf", inputnum1, inputnum2);

void(*func[4])(double, double)={&addition, &subtraction, &division, &multiplication};
(*func[inputfunc-1])(inputnum1, inputnum2);
return(0);
}
}
void addition(double number1, double number2)
{
double answer;
answer=number1+number2;
printf("Addition of the two numbers = %lf + %lf = %lf\n", number1, number2, answer);
return;
}

void subtraction(double number1, double number2)
{
double answer;
answer=number1-number2;
printf("By subtracting the two numbers results are %lf - %lf = %lf\n", number1, number2, answer);
return;
}

void multiplication(double number1, double number2)

{
double answer;
answer=number1*number2;
printf("By multiplying the two numbers results are %lf * %lf = %lf\n", number1, number2, answer);
return;
}



void division(double number1, double number2)

{
double answer;
answer=number1/number2;
printf("By dividing the two numbers results are %lf / %lf = %lf\n", number1, number2, answer);
return;
}
/code
Last edited on
Edit the post if you can to make it a lot easier to help, you need a [/code] at the bottom
when you are reading the two numbers (inputnum1,inputnum2)
you didnt put the (&) before them.
Sometimes the easy ones are the hardest to find. Thank you coder1, I struggled 6 hours trying to find that.
you're welcome, i use cin,cout isnt it easier?
I find cin,cout to be a lot more "error proof". always good to be proficient in as many programming formats as possible though.
Or the fact that cin and cout are c++ and not c and you can do more things with them than puts or printf and the other c i/o things.
Topic archived. No new replies allowed.