Okay, so my assignment for my C class is to generate a program that will allow the user to enter data for a stock and calculate the amount of stocks that ended up being positive, negative, and neutral.
I tried to do this using one stock, here is my code;
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
Code:
void main()
{
float Neg;
float incst;
float shrs;
float bpps;
float crnt;
float crntcst;
float yrfes;
float pft;
float tpft;
printf("IMB number of shares:");
scanf("%f", &shrs);
printf("IBM buying price per share: ");
scanf("%f", &bpps);
printf("IBM current price per share: ");
scanf("%f", &crnt);
printf("IBM yearly Fee: ");
scanf("%f", &yrfes);
incst = shrs*bpps;
crntcst = shrs*crnt;
pft = crntcst - incst - yrfes;
tpft = pft;
printf("The initial cost is %0.2f\n", incst);
printf("The Current cost is %0.2f\n", crntcst);
printf("The profit is %0.2f\n", pft);
if (pft < 0 )
{
int Sum;
int Neg;
Sum = 0;
int add;
add = 1;
Neg=Sum -= add;
printf("given stock is negative");
}
else if (pft > 1)
{
printf("given stock is positive");
}
else if (pft == 0)
{
printf("given stock did not change");
}
printf("the negatives were %d", Neg);
system("pause");
}