|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Access Programming - Having trouble writing a program
1. Write a c++ program to decide if the coefficients of a quadratic equation have real roots. The three choices will be to write the message "zero divide" when A is zero, write the message "No real roots" if the discriminant is negetive and find the two roots when there is no error condition. Do not find the roots if there is an error condition.
2. Use Nested decision to do the three parts of the algorithm above. 3. Write a sentinel controlled loop while loop based on a charector value to control the loop. 'q' or 'Q' will terminate the loop; any other value will continue processing. Read the value from the keyboard and write to the monitor. Use the inputs given below. Do not use a do-while loop. If the first input is 'q' the program should bypass the loop. 4. Document the program properly. Be sure to set the isoflags, setprecision and showpoint. Use a setprecision of 3. Also use setw for each numeric output. 5. Libraries needed; iostream, cmath, iomanip. (add the .h, math.h for older compilers. Sample input: For charector variable, and A, B, and C respectivly. T 2.0 -3.0 -7.0 T 0.0 5.5 1.3 K 3.0 -1.0 10.0 Q // the sentinel value Sample output: The two roots are -1.266 and 2.766(first input above) Zero divide(second input above) No real roots(third input above) Inputs: M 0.0 -1.4 4.9 K 3.0 -2.0 -5.0 T 2.0 3.0 4.0 Q Output: as described above, there should be 3 seperate answers. I got this but wont work blah im so terrible at c++ :/ #include <iostream> #include <iomanip> #include "cmath" //im guessing this is some type of external .h double a,b,c,answ,d; void GetEqn() { char chk; for (int x=1; x<=3; x++) { std::cin>>chk; if (chk == 'q' || chk == 'Q') goto stop; //Stops program if enabled std::cout<<"Please input a: "; std::cin>>a; std::cout<<"Please input b: "; std::cin>>b; std::cout<<"Please input c: "; std::cin>>c; answ=b*b; answ-=4*a*c; if(answ>0) d=1; //cout if(answ=0) d=0; //cout if(answ<0) d=-1; //cout } stop: std::cout<<"Quitted"; } int main() { return 0; } |
![]() |
| Viewing: ASP Free Forums > Other > Programming Help > Access Programming - Having trouble writing a program |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|