function c++ how can i improve my code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

function c++ how can i improve my code

The C++ Marks need to entered in the CPP ( ) function, the Mathematics marks need to entered in the Mathematics ( ) function and the Physics marks need to be entered in the Physics ( ) function Solve this problem by using Function with Parameters (not Global Variables). The output of the desired program is given below: Please Enter Your C++ Marks:67 Your C++ Marks is:67 Please Enter Your Mathematics Marks:78 Your C++ Marks is:67 Your Mathematics Marks is:78 Your Average Marks is: 72.5 Please Enter Your Physics Marks:65 Your C++ Marks is:67 Your Mathematics Marks is:78 Your Physics Marks is:65 Your Average Marks is: 70.0 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ using namespace std; void CPP(); void Mathematics () ; void Physics(); float CppMarks,mathsMarks, physicsMarks, averageCppMaths, AverageCppMathsPhysics; CPP(float CppMarks) { cout<<"Please Enter Your C++ Marks: "; cin>>CppMarks; cout<<"Your C++ Marks is: "<<CppMarks<<endl; } Mathematics (float mathsMarks, float CppMarks ) { cout<<"Please Enter Your Mathematics Marks: "; cin>>mathsMarks; cout<<"Your C++ Marks is: "<<CppMarks<<endl; cout<<"Your Mathematics Marks is: "<<mathsMarks<<endl; averageCppMaths=(mathsMarks+CppMarks)/2 cout<<"Your Average Marks is: "<<averageCppMaths<<endl; Physics() } Mathematics (CppMarks,mathsMarks) Physics() { cout<<"Please Enter Your Physics Marks: "; cin<<physicsMarks; cout<<"Your C++ Marks is: "<<CppMarks<<endl; cout<<"Your Mathematics Marks is: "<<mathsMarks<<endl; cout<<"Your Physics Marks is: "<<physicsMarks<<endl; AverageCppMathsPhysics=(physicsMarks+mathsMarks+CppMarks)/3; cout<<"Your Average Marks is: "<<AverageCppMathsPhysics<<endl; } int main(int argc, char** argv) { CPP(); Mathematics () ; Physics(); }

14th May 2019, 1:47 PM
Mufaro Mudzingwa
Mufaro Mudzingwa - avatar
1 Answer
0
I think you should use the "switch statements"
8th Jun 2020, 6:28 AM
Naveed
Naveed - avatar