Is main function mandatory in glsl shaders?

In C++, how do I output the courseGrade in the main function?

  • /* Program Problem: The function printGrade in Example 5-10 is written as a void function to compute and output the course grade. The course grade is passed as a parameter to the function printGrade. Re-Write the function printGrade as a value returning function so that it computes and returns the course grade. (The course grade must be output in the function main.) Also, change the name of the function to calculateGrade. */ The Code: #include <iostream> #include <cstdlib> #include <iomanip> using namespace std; double calculateGrade (double letter); int main() { double courseScore; cout<<"Enter The student Score: "<<endl; cin>> courseScore; cout<<"The Student's Course Grade: "<<setprecision(1)<<fixed<<courseScore<<... if (calculateGrade(courseScore)){ cout<<"Letter Grade: "<<endl; } system("pause"); return 0; } double calculateGrade (double letter) { if (letter>=90) { cout<<" A"<<endl; return true; } else if (letter>=80){ cout<<"B"<<endl; return true; } else if (letter>=70){ cout<<"C"<<endl; return true; } else if (letter>=60){ cout<<"D"<<endl; return true; } { cout<<"F"<<endl; return true; } } ------------------------------ The code is working fine but the only issue that I am having is the output Here when I get: When I input 70 Output: The Student Score is 70.0 C Letter Grade: _____________ I am trying to get it output like this: The Student Grade: 70.0 Letter Grade: C How can i fix it this way?

  • Answer:

    Comments: Your program outputs inside the function calculateGrade(), not in main(), so it does not satisfy the requirements by your instructor. Your calulateGrade() also does not return the letter grade either, as per the program requirements. Try this instead: #include <iostream> #include <cstdlib> #include <iomanip> using namespace std; double calculateGrade (double letter); int main() { double courseScore; cout<<"Enter The student Score: "<<endl; cin>> courseScore; cout<<"The Student's Course Grade: "<<setprecision(1)<<fixed<<courseScore<<... /* --------------------output result of calculateGrade()------------------------... */ cout<<"Letter Grade: "<<calculateGrade(courseScore)<<endl; system("pause"); return 0; } char calculateGrade (double letter) /* ---------------------------------------... calculateGrade() takes a parameter, letter, of type double and returns a result of type char. ----------------------------------------... */ { if (letter>=90) return "A"; /* ---note: return terminates execution inside the function, so nested if- else if's are unecessary as if condition is satisfied, program flow will never reach other if statements. ---*/ if (letter>=80) return "B"; if (letter>=70) return "C"; if (letter>=60) return "D"; return "F"; }

djp32563 at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

Comments: Your program outputs inside the function calculateGrade(), not in main(), so it does not satisfy the requirements by your instructor. Your calulateGrade() also does not return the letter grade either, as per the program requirements. Try this instead: #include <iostream> #include <cstdlib> #include <iomanip> using namespace std; double calculateGrade (double letter); int main() { double courseScore; cout<<"Enter The student Score: "<<endl; cin>> courseScore; cout<<"The Student's Course Grade: "<<setprecision(1)<<fixed<<courseScore<<… /* --------------------output result of calculateGrade()------------------------… */ cout<<"Letter Grade: "<<calculateGrade(courseScore)<<endl; system("pause"); return 0; } char calculateGrade (double letter) /* ---------------------------------------… calculateGrade() takes a parameter, letter, of type double and returns a result of type char. ----------------------------------------… */ { if (letter>=90) return "A"; /* ---note: return terminates execution inside the function, so nested if- else if's are unecessary as if condition is satisfied, program flow will never reach other if statements. ---*/ if (letter>=80) return "B"; if (letter>=70) return "C"; if (letter>=60) return "D"; return "F"; }

djp32563

Try This (sample run): http://codepad.org/hQOoWUtt ___ #include <iostream> #include <cstdlib> #include <iomanip> using namespace std; double calculateGrade (double letter); int main() { double courseScore=80; cout<<"Enter The student Score: "<<endl; cin>> courseScore; cout<<"The Student's Course Grade: "<<setprecision(1)<<fixed<<courseScore; cout<<"\nLetter Grade: "<<endl; if (calculateGrade(courseScore)){ } //system("pause"); return 0; } double calculateGrade (double letter) { if (letter>=90) { cout<<" A"<<endl; return true; } else if (letter<90 && letter>=80){ cout<<"B"<<endl; return true; } else if (letter<80 && letter>=70){ cout<<"C"<<endl; return true; } else if (letter<70 && letter>=60){ cout<<"D"<<endl; return true; } { cout<<"F"<<endl; return true; } }

.#include <keperkjr>

Try This (sample run): http://codepad.org/hQOoWUtt ___ #include <iostream> #include <cstdlib> #include <iomanip> using namespace std; double calculateGrade (double letter); int main() { double courseScore=80; cout<<"Enter The student Score: "<<endl; cin>> courseScore; cout<<"The Student's Course Grade: "<<setprecision(1)<<fixed<<courseScore; cout<<"\nLetter Grade: "<<endl; if (calculateGrade(courseScore)){ } //system("pause"); return 0; } double calculateGrade (double letter) { if (letter>=90) { cout<<" A"<<endl; return true; } else if (letter<90 && letter>=80){ cout<<"B"<<endl; return true; } else if (letter<80 && letter>=70){ cout<<"C"<<endl; return true; } else if (letter<70 && letter>=60){ cout<<"D"<<endl; return true; } { cout<<"F"<<endl; return true; } }

.#include

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.