| Off Topic > Off Topic |
| Programming Megathread |
| << < (111/241) > >> |
| Gytyyhgfffff:
i got lua today and i don't know how i was living without it |
| Ravencroft·:
Ravencroft made a pretty cool program for my c++ exam today --- Code: ---//Exam 2 - Problem 23 #include<iostream> #include<cmath> #include<math.h> using namespace std; int main() { //variables float y, a, b, w, x, q, h, g; int choice; //menu cout<<"This program will will calculate the value of y, w, or q for each variable's designated equation:" <<"\n"<<"\n" <<"Choice 1 calculates the value of y for the equation 'y=10+[(5a)/(3b)]-4b^2' when the user inputs values for a and b." <<"\n" <<"Choice 2 calculates the value of w for the equation 'w=6x^5-15' when the user inputs a value for x." <<"\n" <<"Choice 3 calculates the value of q for the equation 'q=(3/4)h-(7g/6)' when the user inputs values for h and g." <<"\n"<<"\n" <<"Please enter a choice number: "; //menu selection cin>>choice; while(choice>3) { cout<<"That is an invalid selection. Please enter choice number 1-3: "; cin>>choice; } //choice outputs switch(choice) { case(1): { cout<<"You have selected choice 1." <<"\n"<<"\n" <<"Enter a value for a: "; cin>>a; cout<<"Enter a value for b: "; cin>>b; y=10+((5*a)/(3*b))-(4*pow(b,2)); cout<<"y="<<y<<" when a="<<a<<" and b="<<b<<" for the equation 'y=10+[(5a)/(3b)]-4b^2'."; break;} case(2): { cout<<"You have selected choice 2." <<"\n"<<"\n" <<"Enter a value for x: "; cin>>x; w=6*pow(x,5)-15; cout<<"w="<<w<<" when x="<<x<<" for the equation 'w=6x^5-15'."; break;} case(3): cout<<"You have selected choice 3." <<"\n"<<"\n" <<"Enter a value for h: "; {cin>>h; cout<<"Enter a value for g: "; cin>>g; q=(3/4)*h-(7*g/6); cout<<"q="<<q<<" when h="<<h<<" and g="<<g<<" for the equation 'q=(3/4)h-(7g/6)'";} break;} } //end of program --- End code --- |
| Otis Da HousKat:
Not that it has a real impact on the control flow in the switch statement, but if a user enters 0 for example while(choice>3) will not catch it and the program will just end with no indication of what happened. |
| Ravencroft·:
--- Quote from: Anonymous on April 01, 2016, 09:36:56 PM ---Not that it has a real impact on the control flow in the switch statement, but if a user enters 0 for example while(choice>3) will not catch it and the program will just end with no indication of what happened. --- End quote --- Yeah I noticed that after I submitted it. Luckily we haven't started any material on loops yet. I just wanted to see if I could implement one into the program successfully since we start lecture on loops next week. |
| ZSNO:
--- Quote from: Anonymous on April 01, 2016, 10:14:08 PM ---Yeah I noticed that after I submitted it. Luckily we haven't started any material on loops yet. I just wanted to see if I could implement one into the program successfully since we start lecture on loops next week. --- End quote --- ... you have a while loop in the program though |
| Navigation |
| Message Index |
| Next page |
| Previous page |