用vc++写一段程序,当该股票涨幅超过9%时卖出,当该股票跌幅达到5%时卖出 
时间: 2023-03-20 09:00:50 浏览: 15
以下是使用VC++编写的程序,用于检测股票的涨幅并在超过9%时卖出:
```c++
#include <iostream>
using namespace std;
int main() {
double buy_price, current_price, increase_percentage;
cout << "请输入购买价格:";
cin >> buy_price;
cout << "请输入当前价格:";
cin >> current_price;
increase_percentage = (current_price - buy_price) / buy_price * 100;
if (increase_percentage > 9) {
cout << "当前涨幅超过9%,建议卖出!" << endl;
}
else {
cout << "当前涨幅未超过9%,暂不建议卖出!" << endl;
}
return 0;
}
```
该程序先要求用户输入购买价格和当前价格,然后计算涨幅百分比。最后,如果涨幅超过9%,程序将输出一个建议卖出的消息,否则将输出一个暂不建议卖出的消息。
相关问题
当运行打怪游戏时,写一段基于vc++的得分胜利代码,当得分为20时胜利,得分命名为count
假设得分变量 `count` 已经在程序中定义,在游戏过程中每次得分都会更新它的值,可以使用以下代码来判断是否胜利:
```c++
if (count >= 20) {
// 胜利
// 在此处添加胜利的代码
}
```
当得分 `count` 的值大于等于 20 时,条件表达式 `count >= 20` 的结果为真,就会执行 `if` 语句中的代码块。你可以在这里添加胜利的代码,比如弹出一个胜利的提示框,播放胜利的音效,或者调用一个胜利的函数来完成胜利后的操作。
vc++股票图形程序源码
vc是Visual C++的简称,是一种用于Windows平台开发的集成开发环境。股票图形程序源码,一般用于实时展示股票价格走势、交易量等数据信息,具有分时图、K线图等功能。
以下是一个基于Visual C++的简单股票图形程序的源码示例:
```
#include <iostream>
#include <windows.h>
#include <stdio.h>
#include <conio.h>
using namespace std;
void drawChart(int data[], int size) {
const int maxValue = 100; // 最大允许的数据值
const int chartWidth = 80; // 图表宽度
const int chartHeight = 25; // 图表高度
// 清屏
system("cls");
for (int i = 0; i < size; i++) {
// 计算当前数据在图表中的高度
int barHeight = chartHeight * data[i] / maxValue;
// 打印垂直坐标轴
if (i % 5 == 0) {
cout << setw(4) << maxValue - maxValue * i / chartHeight;
} else {
cout << setw(4) << " ";
}
// 打印柱状图
for (int j = 0; j < chartWidth; j++) {
if (j == chartWidth / 2 || (j == chartWidth / 2 + 1 && data[i] == 0)) {
cout << ".";
} else if (j == chartWidth / 2 && barHeight > 0) {
cout << "|";
} else if (j > chartWidth / 2 && j <= chartWidth / 2 + barHeight) {
cout << "-";
} else {
cout << " ";
}
}
cout << endl;
}
// 打印水平坐标轴
for(int i = 0; i < chartWidth; i++) {
cout << "-";
}
cout << endl;
}
int main() {
const int dataSize = 30; // 数据大小
int data[dataSize] = {10, 20, 15, 50, 30, 70, 45, 80, 85, 75, 60, 70, 65, 80, 90, 70, 40, 35, 55, 65, 75, 85, 95, 80, 60, 55, 45, 40, 30, 20};
// 渲染图表
drawChart(data, dataSize);
_getch();
return 0;
}
```
这个示例中,我们使用Visual C++编写了一个简单的股票图形程序。程序通过调用函数`drawChart`来绘制股票走势图。在函数中,我们首先设置一些参数,比如图表的最大数据值,图表的宽度和高度。然后通过循环遍历数据数组,并根据每个数据的值计算出对应的柱状图的高度,在控制台上打印出相应的图形。最后,我们在`main()`函数中调用`drawChart`函数并传入示例数据进行渲染。用户可以通过按下任意键退出程序。
这个示例只是一个简单的股票图形程序的源码,实际的股票图形程序需要根据具体需求进行扩展和改进。
相关推荐















