Ok so i am working on some school work in Visual Studio 2015 for the first time and my program will not go into an if statements and just exits with code 0, i tried removing the if statement and it works but I need to have it.
#include <stdio.h>
void main() {
char c1, c2;
int controlPoint;
int counter, counterTwo;
float intSingle;
int isTrue = 0;
float* x;
float* y;
float* fx;
float sum = 0;
float temp;
int k;
printf(" \n Please select an option");
printf(" \n Press i to do an interlopation");
printf(" \n Press q to quit");
scanf("%c", &c1);
if (c1 == 'q' || c1 == 'Q') {
printf("Now Quiting");
exit(0);
}
else if (c1 == 'i' || c1 == 'I') {
printf(" \n Do a Lagrange Interlopation");
printf(" \n How many control points are there?");
scanf("%d", &controlPoint);
x = malloc(controlPoint * sizeof(float));
y = malloc(controlPoint * sizeof(float));
for (counter = 0; counter < controlPoint; counter++) {
printf("Please Enter the x coordinate for control point #%d: ", counter);
scanf("%f", &x[counter]);
printf("Please Enter the y coordinate for control point #%d: ", counter);
scanf("%f", &y[counter]);
}
}
else {
printf("Invalid Option Quitting");
}
printf("\nPlease select an option");
printf("\n Press s to do single interlopation");
printf("\n Press r to interlope in increments over the entire range");
printf("\n Press q to quit");
scanf("%c", &c2);
if (c2 == 's' || c2 == 'S') {
printf(" \n Interlope Single");
printf(" \n Please enter the value of x you wish to interlope for: ");
scanf("%f", &intSingle);
fx = malloc(controlPoint * sizeof(float));
for (counter = 0; counter < controlPoint; counter++)
{
temp = 1;
int k = counter;
for (counterTwo = 0; counterTwo < controlPoint; counterTwo++)
{
if (k == counterTwo)
{
}
else
{
temp = temp * ((intSingle - x[counterTwo]) / (x[k] - x[counterTwo]));
}
}
fx[counter] = y[counter] * temp;
}
for (counter = 0; counter < controlPoint; counter++)
{
sum = sum + fx[counter];
}
printf("\n Interpolated pair is (%f, %f) ", intSingle, sum);
}
else if (c2 == 'q' || c2 == 'Q'){
printf("Now Quiting");
exit(0);
}
int holder;
scanf("%d", &holder);
}
the problem is when user inputs second option, it just closes if i press s with code 0 i also removed the if statement and the code works fine but i need them