C ++我想在我的字母等级循环中运行我的数组 [英] C++ I want to run my array thew my letter grade loop

查看:116
本文介绍了C ++我想在我的字母等级循环中运行我的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在阵列中有成绩,我希望他们在运行时扔了一个字母I级循环它所以它可以告诉他有多少AI得到了多少BI等等。



I have grades in array and I want the run them threw a letter grade I loop it so It can tell he how many A I got how many B I got and so on.

void StatsList::PrintGradeCount()
{
	double gcount = 0;
	while (int j =! 1);
	{
		gcount = gcount + List[Listindex];
	
	
		



		if (gcount <= 100 && gcount >= 90) {
			cout << "A:" << gcount << endl;
		}
		else if (gcount <= 89 && gcount >= 80) {
			cout << "B:" << gcount << endl;
		}
		else if (gcount <= 79 && gcount >= 70) {
			cout << "C:" << gcount << endl;
		}
		else if (gcount <= 69 && gcount >= 60) {
			cout << "D:" << gcount << endl;
		}
		else if (gcount <= 59 && gcount >= 0) {
			cout << "F:" << gcount << endl;
		}
	}
	
	
	return;
}





我的尝试:



我有一个for循环然后我尝试了,虽然我认为这是错误但可以帮助。



What I have tried:

I had a for loop first then I tried while I think it's wrong but can some one help up.

推荐答案

你做的看起来相当混乱,使用调试器查看代码正在做什么。

What you do looks rather confuse, use the debugger to see what your code is doing.
        if (gcount <= 100 && gcount >= 90) {
    cout << "A:" << gcount << endl;
}
else if (gcount <= 89 && gcount >= 80) {
    cout << "B:" << gcount << endl;
}
else if (gcount <= 79 && gcount >= 70) {
    cout << "C:" << gcount << endl;
}
else if (gcount <= 69 && gcount >= 60) {
    cout << "D:" << gcount << endl;
}
else if (gcount <= 59 && gcount >= 0) {
    cout << "F:" << gcount << endl;
}





独立于其他错误,当gcount为89.5或69.2时,您的代码会失败

代码可以简化处理这种情况,因为所有 if 否则如果我们单个结构你需要学习。

假设gcount在0到100之间:



Independently from other bugs, your code fail when gcount is 89.5 or 69.2
The code can handle this case with simplifying because all the if and else if us a single structure that you need to learn.
assuming gcount is between 0 and 100:

        if (gcount >= 90) {
    cout << "A:" << gcount << endl;
}
else if (gcount >= 80) {
    cout << "B:" << gcount << endl;
}
else if (gcount >= 70) {
    cout << "C:" << gcount << endl;
}
else if (gcount >= 60) {
    cout << "D:" << gcount << endl;
}
else if (gcount >= 0) {
    cout << "F:" << gcount << endl;
}







你应该学会尽快使用调试器可能。而不是猜测你的代码在做什么,现在是时候看到你的代码执行并确保它完成你期望的。



调试器允许你跟踪执行逐行检查变量,你会看到它有一个停止做你期望的点。

调试器 - 维基百科,免费的百科全书 [ ^ ]

掌握Visual Studio 2010中的调试 - A初学者指南 [ ^ ]



调试器在这里向您展示您的代码正在做什么,您的任务是与它应该做什么进行比较。 />




这是林ks由语言的作者参考C和C ++的书籍。注意,C是C ++的祖先,所以知道C对C ++总是有用。

C编程语言 - 维基百科,免费的百科全书 [ ^ ]

https://hassanolity.files.wordpress.com/2013/11/the_c_programming_language_2。 pdf [ ^ ]

http://www.ime.usp。 br / ~pf / Kernighan-Ritchie / C-Programming-Ebook.pdf [ ^ ]



C ++编程语言 [ ^ ]




You should learn to use the debugger as soon as possible. Rather than guessing what your code is doing, It is time to see your code executing and ensuring that it does what you expect.

The debugger allow you to follow the execution line by line, inspect variables and you will see that there is a point where it stop doing what you expect.
Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.


Here is links to references books on C and C++ by the authors of the languages. Note than C is the ancestor of C++, so knowing C is always useful with C++.
The C Programming Language - Wikipedia, the free encyclopedia[^]
https://hassanolity.files.wordpress.com/2013/11/the_c_programming_language_2.pdf[^]
http://www.ime.usp.br/~pf/Kernighan-Ritchie/C-Programming-Ebook.pdf[^]

C++ Programing Language[^]


这篇关于C ++我想在我的字母等级循环中运行我的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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