My intention was for this program to be capable of transcribing piano notes into alto saxophone notes and vice versa (depending on whether the user selects P or p for Piano, or S or s for alto saxophone).
When I run this code, the altoSaxKey function in main automatically comes first, which prevents me from ever activating my pianoKey function. This is despite entering "S" or "s" for the instrument, which I assume will allow me to activate pianoKey in the second while loop, rather than altoSaxKey in the first while loop.
Also, when I enter the words "Exit" or "exit," the output window does not close. What should I do to solve these two problems? Thanks!
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
string altoSaxKey(string note) // Originally piano - becoming Alto Sax.
{
string instrument;
if (note == "A")
{
cout << "Gb" << "\n" << endl;
}
else if (note == "Ab")
{
cout << "F" << "\n" << endl;
}
else if (note == "B")
{
cout << "Ab" << "\n" << endl;
}
else if (note == "Bb")
{
cout << "G" << "\n" << endl;
}
else if (note == "C")
{
cout << "A" << "\n" << endl;
}
else if (note == "D")
{
cout << "B" << "\n" << endl;
}
else if (note == "Db")
{
cout << "Bb" << "\n" << endl;
}
else if (note == "E")
{
cout << "Db" << "\n" << endl;
}
else if (note == "Eb")
{
cout << "C" << "\n" << endl;
}
else if (note == "F")
{
cout << "D" << "\n" << endl;
}
else if (note == "G")
{
cout << "E" << "\n" << endl;
}
else if (note == "Gb")
{
cout << "Eb" << "\n" << endl;
}
else if (note != "A" || "Ab" || "B" || "Bb" || "C" || "D" || "Db" || "E" || "Eb" || "F" || "G" || "Gb" || "Exit" || "exit")
{
cout << "Please enter a valid note." << "\n" << endl;
}
return note;
}
string pianoKey(string note) // Originally Alto sax - becoming piano.
{
string instrument;
if (note == "A")
{
cout << "C" << "\n" << endl;
}
else if (note == "Ab")
{
cout << "B" << "\n" << endl;
}
else if (note == "B")
{
cout << "D" << "\n" << endl;
}
else if (note == "Bb")
{
cout << "Db" << "\n" << endl;
}
else if (note == "C")
{
cout << "A" << "\n" << endl;
}
else if (note == "D")
{
cout << "F" << "\n" << endl;
}
else if (note == "Db")
{
cout << "E" << "\n" << endl;
}
else if (note == "E")
{
cout << "G" << "\n" << endl;
}
else if (note == "Eb")
{
cout << "Gb" << "\n" << endl;
}
else if (note == "F")
{
cout << "Ab" << "\n" << endl;
}
else if (note == "G")
{
cout << "Bb" << "\n" << endl;
}
else if (note == "Gb")
{
cout << "A" << "\n" << endl;
}
else if (note != "A" || "Ab" || "B" || "Bb" || "C" || "D" || "Db" || "E" || "Eb" || "F" || "G" || "Gb" || "Exit" || "exit")
{
cout << "Please enter a valid note." << "\n" << endl;
}
return note;
}
int main()
{
string instrument;
string P, p, S, s;
string note;
string A, Ab, B, Bb, C, D, Db, E, Eb, F, G, Gb;
string Exit, exit;
int x = 1;
cout << "Please press P for Piano or S for Alto Saxophone, followed by the Enter key." << endl;
cin >> instrument;
cout << "Press the Enter key once you have provided a musical note." << endl;
cout << "When you are finished providing musical notes, enter the word: Exit." << endl;
while (instrument == "P" || "p" && note != "Exit" || "exit")
{
cin >> note;
cout << x << ": ";
x++;
altoSaxKey(note);
}
while (instrument == "S" || "s" && note != "Exit" || "exit")
{
cin >> note;
cout << x << ": ";
pianoKey(note);
x++;
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire