现在对这一天感到难过,我知道我只需要“=”标志和“>”结束问题。任何提示或建议>?
int main()
{
//Calling in Variables
int data;
int counter;
//Step 1:Prompt the user to pass in a positive integer between (0-50)
cout << "Type in a number between 0-50 to plot your bar: " << endl;
cin >> data;
//Step 2: Error check for bad numbers that have been input.
if(data < 0) {
cout<< "ERROR: " << data << " is not in acceptable range."<< endl;
}
//Step 3:
if(data >= 0 && data <= 50){
for(int counter =1; counter <= data; counter++) {
if(counter % 10 !=0)
cout<< "|";
else(data%5 == 0)
cout << "+";
}
}
else
cout << "BarPlot - End Plot by User Request"
return (0);
}
创建一个简单的条形图绘制器(BarPlot),它在[0 50]之间取一个正整数,并绘制 数字作为一个简单的酒吧。该程序只应接受此范围内的数据。任何负值输入都应该 终止本程序。任何大于50的输入都应该导致错误消息并提示输入另一个 数。
示例输出:
BarPlot - 一个简单的条形图绘图仪:
输入范围[0 50]或负数以终止的数字:
|输入数字:8
| ==== + ==&GT; 8
|输入数字:15
| ==== + ==== | ====&GT; 15
|输入数字:50
| ==== + ==== | ==== + ==== | ==== + ==== | ==== + ==== | ==== + ====&GT ; 50
|输入数字:65
|错误:65不在可接受的范围内。
|输入数字:0
| 0
|输入数字:1
| &GT; 1
|输入数字:5
| ====&GT; 50
|输入数字:-1
BarPlot - 按用户请求结束绘图
答案 0 :(得分:0)
你有一个非常简单的问题,你把它放在一大块文本中就变得复杂了。你有非常简单的逻辑,你想要打印=
除了每个第5和第10个数字。你基本上已经在那里了:
for(int counter =1; counter <= data; counter++) {
if(counter % 10 ==0)
cout<< "|";
else if(counter%5 == 0)
cout << "+";
else
cout << "=";
}
cout << ">" << yournumberthing << endl;
你只需要考虑一下。