卡住了!使用整数、字符到整数转换、ASCII 和 MIDI 进行验证
STUCK! Validation with integers, character to integer conversion, ASCII and MIDI
好吧,所以我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()
后才能编译程序。
如果您正确格式化了代码,则可以自行修复这些错误。
相关文章:
- 如何反转整数参数包
- enum是C++中的宏变量还是整数变量
- 努力将整数转换为链表。不知道我在这里做错了什么
- 整数不会重复超过随机数
- 在C++中手动调整数组大小
- 检查输入是否不是整数或数字
- 弄清楚如何在C++中将整数读入 ASCII
- 使用指针将 ASCII 值添加到整数
- 当我尝试将范围值存储为 8 位的固定宽度整数时,它向我显示一些其他值 [ASCII]
- 如何将ASCII数字转换为从文件中提取的整数
- 将整数转换为ascii值C++
- 在整数中转换ASCII文件列
- wostringstream,Ascii,Unicode,Win32和整数连接到字符串
- 如果我有一个固定大小的填充ascii数字的char数组,我知道它指的是一个无符号整数,那么将其转换为无符号整数的最快方法
- 卡住了!使用整数、字符到整数转换、ASCII 和 MIDI 进行验证
- C++ 堆栈字符串流函数返回整数与 ASCII
- 如何将整数转换为其 ascii 等效项
- 将 0 和 1 的字符串变成一个整数,变成那个 ascii val 中的一个字符
- 我如何读取整数并将其转换为ASCII字符和
- 将整数的十进制值作为其 ASCII 表示形式插入到字符向量中