I have a homework assignment that I have been trying to figure out for over 12 hours now...The program I am trying to write is too complicated to post, so I created a simpler program which lets a user enter two integers and an operation to perform. If someone can help me figure out how to write the pointers correctly so that I get an output, I can probably figure out my homework assignment (I made an attempt with the addFunc). The other problem I am having is that when I take out the pointers to check my algorithms, if you enter in a value other than 'a', 's', 'm', or 'd', it gets stuck in the while loop. Please help. :sad:
#include "input.h"
#include <stdio.h>
#include <ctype.h>
typedef int bool;
#define true 1
#define false 0
void addFunc(int *x, int *y);
void subFunc(int x, int y);
void multFunc(int x, int y);
void divFunc(int x, int y);
int a, b, total;
char operation, throwaway;
bool badOperation;
int main()
{
printf ("Please enter an integer: ");
scanf ("%d", &a);
printf ("Please enter another integer: ");
scanf ("%d", &b);
printf ("Would you like to (a)dd, (s)ubtract, (m)ultiply, or (d)ivide?\n");
scanf ("%c", &operation);
scanf ("%c", &throwaway);
printf ("%c", &operation);
if (operation != 'a' && operation != 's' && operation != 'm' && operation != 'd')
{
badOperation = true;
}
while (badOperation)
{
printf("You must select from 'a', 's', 'm', or 'd'.\n");
scanf("%c", &operation);
scanf("%c", &throwaway);
if (operation == 'a' || operation == 's' || operation == 'm' || operation == 'd')
{
badOperation = false;
}
}
if (operation == 'a')
{
addFunc(a, b);
printf ("The sum is %d.\n", total);
}
if (operation == 's')
{
subFunc(a, b);
printf ("The difference is %d.\n", total);
}
if (operation == 'm')
{
multFunc(a, b);
printf ("The product is %d.\n", total);
}
if (operation == 'd')
{
divFunc(a, b);
printf ("The quotient is %d.\n", total);
}
}
void addFunc(int *x, int *y)
{
int *x = &a;
int *y = &b;
int total;
total = *x + *y;
}
void subFunc(int x, int y)
{
int total;
total = x - y;
}
void multFunc(int x, int y)
{
int total;
total = x * y;
}
void divFunc(int x, int y)
{
int total;
total = x / y;
}