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

时间:2015-01-31 13:43:09

标签: c++

好的,所以我的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 characters\n";
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-G\n";
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 digit\n";
return false;
}
//Step 4: If note length is 3 note[1] (character 2) must be '#'.
else if(note.length() == 3 && note[1] != '#')
{
"Invalid sharp note\n";
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 you\n";
} //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;
}
输入

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

我两天来一直遇到同样的问题;每当我构建解决方案时,它都会返回相同的错误:“致命错误C1075,在最后一个大括号'{'匹配之前找到的文件结尾”。

如果有人能指出我解决这个问题的正确方法,那将非常感谢!!

1 个答案:

答案 0 :(得分:0)

int CalculateNoteNumber(string tempName)结束时你错过了} 您还必须删除int main()之后的; ,以便编译您的程序。

如果您已正确格式化代码,则可以自行解决这些错误。