我几乎完成了代码,我只需要弄清楚如何使用 cout 和 cin 使用户输入字符的值和三角形的高度,谢谢这是我所有的代码硬编码。
我觉得我的措辞是错误的,基本上程序应该使用我在下面创建的函数 drawline 绘制一个三角形,当我编译并运行它时,如果我输入 1,它会要求我输入用户选择它运行 if (userChoice == 1){} 基本上我想要一个 cin 和 cout 代码结构,允许他们输入 lineLength 和 displayChar 的值。
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
void drawLine (int lineLength, char displayChar);
void placePoint (int lineLength) ;
int main()
{
int userChoice = 0;
cout << "**********************************" << endl;
cout << "* 1 - DrawTriangle *" << endl;
cout << "* 2 - Plot Sine graph *" << endl;
cout << "* 3 - Exit *" << endl;
cout << "Enter a selection, please: " << endl;
cin >> userChoice;
int x,y,t =0;
char displayChar = ' ';
int lineLength = 0;
double sinVal= 0.00;
double rad = 0.00;
int plotPoint = 0;
if (userChoice == 1)
for (int x=1; x <= lineLength; x=x+1) {
drawLine ( x, displayChar);
}//end for
for (int y=lineLength-1; y >= 1; y=y-1) {
drawLine ( y, displayChar );
}//end for
}//end main at this point.
void drawLine (int lineLength, char displayChar)
{
for (int x=1; x <= lineLength; x=x+1) {
cout << displayChar;
}
cout << endl;
for (int y=y-1; y >= 1; y=y-1) {
cout << displayChar;
}
cout << endl;
} //end drawline