卡住了!使用整数、字符到整数转换、ASCII 和 MIDI 进行验证

STUCK! Validation with integers, character to integer conversion, ASCII and MIDI

本文关键字:整数 ASCII MIDI 验证 转换 字符      更新时间:2023-10-16

好吧,所以我C++知识太少了,我一直在慢慢拼凑一个代码,但老实说,我很惊讶我能走到这一步。

只是为了概述我的任务。要求用户输入几个音符(音符,C-B,包括夏普斯,跨越 9 个八度)以创建旋律线,然后再次输入低音线。输入注释后,注释长度也必须

#‎include‬ <iostream>
#include <string>
#include <vector>
using namespace std;
int notenumber;
struct noteStorage
{
string noteName;
int midiNumber;
int noteLength;
};
///////////////////////////////////////////////////////////////////////////////////////////////
//VALIDATION FOR NOTE NAME
bool ValidateNote(string note)
{
// Step 1: If note name length is less than 2 OR more than 3, return false
if (note.length() <2 || note.length() >3) 
{
cout<<"Note length must be 2 or 3 charactersn";
return false;
}
//Step 2: If true, the note must be/(or be) between A and G
else if(tolower(note[0])<'a' || tolower(note[0]) >'g') 
{
cout<<"Note must be A-Gn";
return false;
}
//Step 3: If true, the last character must be a digit
else if(isdigit(note[note.length()-1]) == false)
{
cout<<"Last character must be a digitn";
return false;
}
//Step 4: If note length is 3 note[1] (character 2) must be '#'.
else if(note.length() == 3 && note[1] != '#')
{
"Invalid sharp noten";
return false;
}
return true;
}
/////////////////////////////////////////////////////////////////////////////////////////
//VALIDATION FOR NOTE LENGTH
bool ValidateNoteLength (int length)
//Step 1 - If notelength is not a digit, return FALSE
{
if (length == false)
{
cout<<"Note length must be a digit/number, please re-enter";
return false;
}
//Step 2 - If notelength is less than or equal to 0 or more than 16, return FALSE
if (length <= 0 || length > 16)
{
cout<<"Note length value cannot be less than 1 or more than 16, please re-enter";
return false; 
}
return true;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
int CalculateNoteNumber(string tempName)
{
int Octave;
int Note;
tempName[0] = toupper(tempName[0]);
Octave = ((tempName[tempName.length()-1]) -48) * 12;
if (tempName.length() == 2)
{ 
if(tempName[0] == 'C')
{
return notenumber = 0;
}
else if(tempName[0] == 'D')
{
return notenumber = 2;
}
else if(tempName[0] == 'E') 
{
return notenumber = 4;
}
else if(tempName[0] == 'F') 
{
return notenumber = 5; 
}
else if(tempName[0] == 'G') 
{
return notenumber = 7;
}
else if(tempName[0] == 'A') 
{
return notenumber = 9; 
}
else
{
return notenumber = 11;
}
}
else if (tempName.length() == 3)
{ 
if(tempName[0] == 'C')
{
return notenumber = 1;
}
else if(tempName[0] == 'D')
{
return notenumber = 3;
}
else if(tempName[0] == 'F') 
{
return notenumber = 6; 
}
else if(tempName[0] == 'G') 
{
return notenumber = 8;
}
else
{
return notenumber = 10; 
}
}
int main();
{
noteStorage noteData[8];
//string note;
for (int i = 0; i < 8; i++)
{
cout<<"Please enter note: " << i << ": ";
while (1)
{
string tempName;
cin>>tempName;
int noteNumber = CalculateNoteNumber(tempName);
if (ValidateNote(tempName) == true)
{
noteData[i].noteName = tempName;
break;
}
else
{
cout << "Please enter correctly: ";
}
} //end first while
cout<<"Please enter note length: ";
while (1)
{
int tempLength;
cin>>tempLength;
if (ValidateNoteLength(tempLength) == true)
{
noteData[i].noteLength = tempLength;
break;
}
else
{
cout << "Please enter correctly: ";
}
}//end while 2
cout<<"Thank youn";
} //end for
cout<<"Your note and note lengths are: "<<endl;
for (int i = 0; i < 8; i++)
{
cout<<noteData[i].noteName<<"Length: ";
cout<<noteData[i].noteLength<<endl;
}
system("pause");
return 0;
}

输入(以毫秒为单位的值)。输入音符名称和音符长度后,控制台会将音符名称转换为相应的 midi 编号,并将所述音符编号、音符长度和音符名称输出回用户。

两天来我一直遇到同样的问题;每次我构建解决方案时,它都会返回相同的错误:

"致命错误 C1075,在最后一个大括号'{'之前找到的文件结尾是 匹配"。

如果有人能指出我解决这个问题的正确方法,将不胜感激!!

您在int CalculateNoteNumber(string tempName)末尾错过了一个 }
您还必须删除 ; int main()后才能编译程序。

如果您正确格式化了代码,则可以自行修复这些错误。