Function is not worked in C

Bow

Joined
Jun 27, 2023
Messages
1
Reaction score
0
There is my code in C to create a menu, but when I run my program, there was a problem:
- Input was scanned by after scanf funtion, it did not run the next function.

[ CODE ]::
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int quadequation (int n);
int bankDeposit(int n);

int n, choose;
double a, b, c, x, x1, x2, delta, p, d, y, r;
int main() {
do {
system ("cls");
printf ("MENU\n");
printf ("1. Quadratic equation\n");
printf ("2. Bank deposit problem\n");
printf ("3. Quit\n");
printf ("Choose your option: ");
scanf ("%d", &choose);
switch(choose){
case 1: {
printf ("Quadratic Equation: ax^2+ bx +c = 0\n");
printf ("Type a: ");
scanf ("%lf", &a);
printf ("Type b: ");
scanf ("%lf", &b);
printf ("Type c: ");
scanf ("%lf", &c);
quadequation(n);
break;
}
case 2: {
printf ("Bank deposit\n");
printf ("Your deposit: ");
scanf ("%lf", &d);
printf ("Year number: ");
scanf ("%lf", &y);
printf ("Yearly rate: ");
scanf ("%lf", &r);
bankDeposit(n);
break;
}
case 3: {
exit (0);
break;
default:
printf ("Choose again!");
}
}
getch ();
} while (choose >=1 || choose <=3);
}

int quadequation (int n){
if (a!= 0){
delta= pow(b,2)-(4*a*c);
if (delta <0){
printf ("No solution");
}else if (delta = 0){
x= -b/2*a;
printf ("Double solution: x1 = x2 = %lf ", x);
}else if (delta >0){
x1= ( -(b) + (sqrt(delta)) )/2*a;
x2= ( -(b) - (sqrt(delta)) )/2*a;
printf ("There are 2 discriminant solutions:\n");
printf ("x1 = %lf ", x1);
printf ("x2 = %lf ", x2);
}
} else if (a=0){
printf ("This is a linear equation"); // bx+c=0
x= (-c)/b;
printf ("x = %lf", x);
}

return 0;
}

int bankDeposit(int n){
if (d<=0 || r <0 || y<0){
printf ("Type valid value!");
}
p = d*(pow((1+r),y));
printf ("Your money after %0.0lf year: %0.0lf", y, p);
return p;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top