I am taking C to fullfil a requirement, but I do have some genuine interest in it. I will most likely see it later on in my life, however, so far I am not enjoying it. Things aren't working for me and I guess I am not understand the details that are required to understand C programming. I am going to give you what I wrote for my last assignment. If someone could help me understand why a few of these issues are happening I would really appreciate it. I use Dev C++ as a compiler.
1) the command prompt will not stop shutting off once I've entered the desired characters and numbers into the line.
2) I can't get " % " used correctly in an equation. I need it used as a remainder and it reads as a %d or %f command.
3) my intA values keep getting made up in random integers.
4) I don't think I am setting up the arithmetic right.
I am not asking for someone to do the work for me, but I am trying to better understand this. Below is the assignment (how the program should look) and below that is what I turned in, my next assignment is a variation of this so I need to understand this so I can move on. thanks!
This program will prompt the user for 3 arithmetic expressions and display the results of each. The expressions are:
* (a * a) + (a / b) + (c % a)
o a, b, and c are INT values chosen by the user
o The user must enter the expression with the exact parentheses, spaces, and operators shown
o The user may enter any valid values for the variables
o The result is an INT value
* (a / b) * (b / a)
o a and b are FLOAT values chosen by the user
o The user must enter the expression with the exact parentheses, spaces, and operators shown
o The user may enter any valid values for the variables
o The resuld should be displayed with 3 decimal points of precision
* (a - b) % (int)(c * d)
o a and b are INT values chosen by the user
o c and d are FLOAT values chosen by the uer
o The user must enter the expression with the exact parentheses, spaces, and operators shown
o The user may enter any valid values for the variables
o The result is a FLOAT value
Your program must read the operators, parentheses, and values in the expressions, and then display the result. Here is an example of how the program dialog should look:
Enter '(int * int) + (int / int) + (int % int)': (12 * 5) + (12 / 5) + (1 % 5)
(12 * 5) + (12 / 5) + (1 % 5) = 63
Enter '(float / float) * (float / float)': (1.54 / 0.2313) * (-3.5234 / 0.1232)
(1.540 / 0.231) * (-3.523 / 0.123) = -190.413
Enter '(int - int) % (float * float)': (10 - 4) % (4.15 * 6.54)
(10 - 4) % (4.150000 * 6.540000) = 6
my code:
Code:#include <stdio.h> int main() { int varA, varB, varC, int1, varD, varE, equals; float floatA, floatB, floatC, floatD, floatE, floatF, f1sum, fsum; printf("Enter '(intA * intA) + (intA / intB) + (intC '%' intA)': "); scanf ("%d%d%d%d%d%d", &varA, &varB, &varA, &varB, &varC, &varA); equals = (varA * varB) + (varA / varB) + ((varC) % (varA)); printf("(%d * %d) + (%d / %d) + (%d '%' %d) = %d \n\n", varA, varB, varA, varB, varC, varA, equals); printf("Enter '(float / float) * (float / float)': "); scanf ("%f%f%f%f", &floatA, &floatB, &floatC, &floatD); f1sum = (floatA / floatB) * (floatC / floatD); printf("(%f / %f) * (%f / %f) = %.3f \n\n", floatA, floatB, floatC, floatD, f1sum); printf("Enter '(int - int) % ((int)(float * float))': "); scanf ("%d%d%f%f", &varA, &varB, &floatE, &floatF); fsum = (varD - varE) % (int1)*(floatE * floatF); printf("(%d - %d) % (%d)(%f * %f) = fsum \n", varD, varE, floatE, floatF, int1, fsum); scanf ("%*c"); return 0; }