【发布时间】:2014-01-04 15:59:40
【问题描述】:
我正在编写一个程序,允许我输入我的名字并提取不同的学期,然后输入成绩,然后能够计算我的班级平均分和 GPA,仅供我自己在课程中参考。
我遇到的问题是结构以及它们如何与多功能程序一起使用。在我的课程中,我们没有涉及到这一点,我现在花了一段时间寻找答案,但找不到答案。以下是我当前的代码:
using namespace std;
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char gettingName();
class Student{
public:
double semesterClass[20][20]; //first is for semester, second is for which class
char name[20];
int semester;
int numOfCourses;
};
int main(int argc, char **argv)
{
Student info;
gettingName();
cout << "Hi my name is: " << name.info << endl;
return 0;
}
char gettingName()
{
Student info;
char YesNo[5];
char boolean[1] = {'T'};
char yes[3] = {'Y','e','s'};
char yes2[3] = {'Y','E','S'};
char yes3[3] = {'y','e','s'};
char yes4[1] = {'Y'};
char yes5[1] = {'y'};
while(boolean[0] == 'T'){
cout << "What is your name? ";
cin >> info.name;
cout << endl;
cout << "Is your name " << info.name << "?"<<endl; //accepted input will be Y,y,YES,Yes,yes
cin >> YesNo;
//if input does not equal any of the accepted inputs, then loop until it does
if((strcmp(YesNo,yes) == 0) || (strcmp(YesNo,yes2) == 0) || (strcmp(YesNo,yes3) == 0) || (YesNo[0] == yes4[0]) || (YesNo[0] == yes5[0])){
boolean[0] = 'F';
}
}
return 0;
}
我的问题:我该如何修复范围,以便我可以调用“gettingName”函数,让该人输入他们的姓名,(正确输入(已经有效))然后能够访问和在main函数中打印?
【问题讨论】: