确定扬声器C和x2B的电流输出+;初学者 最近,我开始在大学学习C++,并被要求用这样的序列:“*/*”来做“*”循环序列: * *** ***** ******* ********* ********* ******* ***** *** *

确定扬声器C和x2B的电流输出+;初学者 最近,我开始在大学学习C++,并被要求用这样的序列:“*/*”来做“*”循环序列: * *** ***** ******* ********* ********* ******* ***** *** *,c++,volume,speaker,C++,Volume,Speaker,[无限期继续,直到到达x行,其中x在开始处指定] 如果您需要可视化,我是如何做到的: #include<iostream> #include<windows.h> using namespace std; int main() { int hFar=0; //Variable that will be used to find out how many parts into the sequence the user would like to travel. uns

[无限期继续,直到到达x行,其中x在开始处指定]

如果您需要可视化,我是如何做到的:

#include<iostream>
#include<windows.h>

using namespace std;

int main() {
int hFar=0; //Variable that will be used to find out how many parts into the sequence the user would like to travel.
unsigned long int fibSequenceA = 0; //Unsigned doesn't overflow as easilly. This is the first value of the fibunacci sequence, it's defined as 0 to start.
unsigned long int fibSequenceB = 1; // Second Value of fibbunacci sequence. Defined at 1 to start.
int sPart = 1;//Used for the * sequence, it is the part of the sequence that the loop is on. It changes dynamically by either +2 or -2 every loop.
int cValue = 0;// also for the * sequence, it is the current number of * typed.
int sDirection = 0; // used to change from subtracting 2, and adding 2.
int redo = 1; // used to ensure that every 9 and every 1 the sequence repeats that number a second time. Starts at one because the sequence starts with only 1 single * rather then 2 *.

cout << "How far into the second sequence would you like to travel?" << endl; //Requests how far into the * sequence you'd like to go.
        cin >> hFar; //inputs answer into variable.
        for(int i = 0; i < hFar; i++ ) {//begins for statement. Notice there's no hfar/2. There will only be 1 output per line now.
            while(cValue < sPart) { //Basic while loop to input the ammount of * on the current line. Works by adding a * depending on what part of the sequence it is.
                cout << "*"; //self explainitory.
                cValue++; //raises the cValue in order to keep track of the current number of *. Also prevents infinite loop.
            }
            if(sPart == 9 && redo == 0) { //Checks if the sequence part is 9, meaning that the value begins to reduce to 1 again. But first, it must repeat 9 to keep with the sequence.
                sDirection = 3; //sets the direction to 3 to make sure that the value of sPart stays at 9, instead of reducing by 2.
                redo = 1; //resets the redo.
                cValue = 8; //changes the value of the current number of 8. Not sure if this is important, It gets done again later to make sure anyway.
                sPart = 9; //Changes the sPart to 9, the needed number of *. Also redone later, but to make sure, I kept this here.
            }
            else if(sPart == 9 && redo == 1) { // if the sequence has already redone the 9th *
                sDirection = 1; //sets the direction to 1; The sequence will reverse.
                redo = 0; //returns redo to 0 to ensure that next time it reaches 1, it repeats the 1 * again.
            }
            else if(sPart == 1 && redo == 0) {  //when the value reaches one for the second time, it needs to repeat that value.
                sDirection = 3; //sets the direction to 3 again to stop the change.
                redo = 1; //resets the redo.
                cValue  = 0;//also might be redundant.
            }
            else if(sPart == 1 && redo == 1) { // stops the duplicate number of *
                sDirection = 0; //sets the direction to +2 again.
                redo = 0;//resets the redo.
            }
                            Sleep(50);
            cout << endl; //adds a new line. This ensures that we get a new line after every part rather then 900 * on one line.
            if(sDirection == 0) { //if the direction is positive.
                sPart += 2; //adds 2 to the spart to keep with the sequence.
                cValue = 0; //resets the cValue to 0 so the while statement works again.
            }
            else if(sDirection == 1) { //if the direction is negative
                sPart -=2; //subtracts 2 from the spart to keep with the sequence.
                cValue = 0; //resets the cValue to keep the while statement working.
            }
            else if(sDirection = 3) { //if the change is 
            //Could have been done differently. Could have just set the values to themselves, but it wasn't working. not sure why.
                if(sPart == 9){ //if the spart is currently 9.
                    sPart = 9; //keeps it at 9.
                    cValue = 0; //resets the cValue.
                        }
                else if(sPart == 1){ //if the spart is currently 1
                    sPart = 1; //keeps it at one. 
                    cValue = 0; //resets the cValue.
                }
            }
        }
    return 1;//ends the code.
}
#包括
#包括
使用名称空间std;
int main(){
int hFar=0;//变量,用于确定用户希望在序列中移动多少部分。
unsigned long int fibSequenceA=0;//unsigned不容易溢出。这是fibuncai序列的第一个值,它定义为0开始。
unsigned long int fibSequenceB=1;//fibbunacci序列的第二个值。从1开始定义。
int sPart=1;//用于*序列,它是循环所在序列的一部分。每个循环都会以+2或-2动态变化。
int cValue=0;//同样对于*序列,它是当前键入的*数。
int sddirection=0;//用于从减去2到添加2进行更改。
int redo=1;//用于确保序列每9次和每1次重复该数字一次。从1开始,因为序列开始时只有1个*而不是2*。

请不要觉得被冒犯了,但老实说,这是我迄今为止看到的最好的例子,因为太多的注释使代码几乎无法理解。如果(sddirection=3)行中有一个拼写错误
,你应该使用
=
操作符。你知道在给定的时间点知道声音的音量不是一件小事吗?声音是一个波,它的振幅是音量。在某个时间点,波不移动……我知道有很多评论,我的导师希望我在每一行上输入评论来帮助我“学习”我只是复制了我已有的代码,而且,我通常会使用非常明亮的颜色来添加注释,这样更容易忽略它们,它们有点分散注意力。tobi303,我正在尝试获取“音量”例如,如果一个人的电脑音量达到最大,但没有播放任何音乐,电脑将不会发出声音,代码应为“0”,或者如果电脑发出声音,则应为>0。打开Kastle,谢谢。我没有注意到这一点。
int sPart = x; //x = the current output of the speaker
int cValue = 0 //the current number of "*" output
while([somecondition I'm not sure when i want the sequence to stop yet]) {
while(cValue < sPart) { 
                cout << "*";
                cValue++; 
            }
        cout << endl; //ends the current line, making room for the next value of the volume.
        Sleep(50); //waits 50ms before finding the next volume value.
        sPart = [current speaker value]; //finds the value of the speaker again.
        cValue = 0; //resetting the number of "*" back to zero.
        }
//I just reused the variables from my original code.