我幾乎完成了代碼,我只需要弄清楚如何使用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
只需用'cout'向用戶詢問並用'cin'輸入? –
謝謝我試圖直接使用變量lineLength和displayChar,如果你看到它的字符數量,它會給我你會笑你的頭,它只是不斷迭代 –
這正是我所做的@JoachimPileborg cout << Enter三角形長度的值<< endl; cin >> lineLength; cout <<選擇要使用的字符:<< endl; cin >> displayChar; –