我一直在尝试如何解决这个问题 [英] How do I fix this, I have been trying

查看:223
本文介绍了我一直在尝试如何解决这个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试创建该程序,这对我来说很难在现实生活中获得帮助,因为我是第二学期唯一的计算机科学专业的学生.

这是c ++.我必须使用数组
我必须制作一个基于分数显示成绩的程序.学生人数取决于用户输入.

A级> = 90
B级> = 80
C级> = 70
D级> = 60
F级< = 59

根据讲师给我的作业,输出必须像这样

输入学生人数:4
输入4个标记:40 55 70 58
学生0分是40,而成绩是C
学生1分是55,而成绩是B
学生2分是70,而成绩是A
学生3分是58,成绩是B

我尝试过的事情:

i have been trying to make create this program, it''s kinda hard for me to get help in real life because I''m the only computer science student in my second semester.

this is c++. I have to use arrays
I have to make a program that shows grades, based on marks. The number of students depends on the user input.

grade A >=90
grade B >=80
grade C >=70
grade D >=60
grade F <=59

based on the homework my lecturer has given me, the output has to be like this

Enter the number of students: 4
Enter 4 marks: 40 55 70 58
student 0 mark is 40 and grade is C
student 1 mark is 55 and grade is B
student 2 mark is 70 and grade is A
student 3 mark is 58 and grade is B

What I have tried:

This is my code: 

#include<iostream>
using namespace std;
int main(){
int students;
int mark;
int x;
char grade[6]={''A'',''B'',''C'',''D'',''F'',''\0''};
cout<<"enter the number of students"<<endl;
cin>>students;
cout<<"enter "<<students<<" marks "<<endl;
for(x=0;x<students;x++){
cin>>mark;
if(mark>=90)
grade[0];
else if(mark>=80)
grade[1];
else if(mark>=70)
grade[2];
else if(mark>=60)
grade[3];
else
grade[4];

cout<<"student "<<students<<" mark is "<<mark<<" and grade is "<<grade[x];
}
}

I don''t know what to do anymore. Help me

推荐答案

此代码:
if(mark>=90)
grade[0];
else if

什么都不做-您可以访问想要的年级字符,但您不执行任何操作.
if测试之前,创建一个名为currentGradechar变量,并在每个if内部将其分配给所需的等级:

Doesn''t do anything - you access the grade character you want, but you don''t do anything with it.
Before the if test, create a char variable called currentGrade and inside each if assign it to the grade you want:

if(mark>=90)
currentGrade = grade[0];
else if

在所有测试完成后,您可以在cout语句中代替grade[x],然后从currentGrade输出成绩:

You can then output the grade from currentGrade after all the tests are complete in your cout statement instead of grade[x]:

cout<<"student "<<students<<" mark is "<<mark<<" and grade is "<<currentGrade;


尝试一下,看看会发生什么!!


Give it a try and see what happens!


您还将这个问题发布在Managed C ++论坛中.请不要重新发布.
You also posted this question in the Managed C++ forum. Please do not repost.


这篇关于我一直在尝试如何解决这个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆