显示函数值
Displaying Functions values?
#include <iostream>
using namespace std;
int hwGrades();
int testGrades();
int projectGrade();
int main(){
hwGrades();
testGrades();
projectGrade();
//I want the average of each function displayed here
}
int hwGrades(){
int hw1,hw2,hw3, hwAverage;
cout << "Enter the grades of your homework." << endl;
cout << "Homework 1: ";
cin >> hw1;
cout << "Homework 2: ";
cin >> hw2;
cout << "Homework 3: ";
cin >> hw3;
hwAverage = (hw1 + hw2 + hw3) / 3;
return hwAverage;
}
int testGrades(){
int test1, test2, test3, testAvgerage;
cout << "Enter the grades for the tests." << endl;
cout << "Test 1: ";
cin >> test1;
cout << "Test 2: ";
cin >> test2;
cout << "Test 3: ";
cin >> test3;
testAvgerage = (test1 + test2 + test3)/3;
return testAvgerage;
}
int projectGrade(){
int project;
cout << "What did you get on your project: ";
cin >> project;
return project;
}
我很难理解这一点,在所有功能完成后,我如何显示用户输入的值?我试过参数,但我没有很好地掌握它。任何帮助都将不胜感激。我基本上理解其他情况,我只是不知道如何在函数完成后使用这些值。
如果你想打印用户输入的值,你需要在读取它们的函数中打印它们。
如果您引用从testGrades()
等函数返回的计算值,您可以将返回值存储在变量中,执行类似的操作
int result = testGrades();
cout << result;
或者您可以直接输出函数的resturn值
cout << testGrades();
相关文章:
- 使用QTreeView,如何通过调用函数只突出显示特定的行/列
- C++ 构造函数未显示输出
- 访问和打印元组中的数据,并使用 C++14 使用模板函数显示数据
- 分段故障 11,从类函数显示动态 C 字符串
- 函数显示( ) 不给出输出
- 如何使用消息框函数显示 BSTR 值
- 用于显示矩阵元素的C 函数显示垃圾值
- 函数显示输出和输入时出现问题
- 简单树插入节点函数显示为空
- 挂钩 winapi 函数显示我 dllimport 错误
- C++中的友元函数显示"variable or feild declared void error"
- 使用 main() 以外的其他函数显示类的对象,但在 main() 中调用;
- 我如何使用函数来计算并使用void函数显示
- 输入两个整数,并使用预定义函数显示最大数字
- 在界面设计中使用函数显示日期
- 我的函数显示垃圾,其他时候它显示干净的结果
- 使用函数显示直方图
- 为什么这个哈希表函数显示编译错误
- c++中友元函数显示错误
- 如何使用时间类和函数显示时间