Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

* What goto alternatives can I use and how can I replace them? Here is my code --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- #include stdafx.h #include #include using namespace std;

* What goto alternatives can I use and how can I replace them?

Here is my code

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#include "stdafx.h"

#include

#include

using namespace std;

// frequency = frequency of A * 2 n / 12

int compute(int& Note_Range, int& Frequency_of_A) {

int Frequency_at_A = Frequency_of_A; double value_n = Note_Range;

double Frequency_A = Frequency_at_A * pow(2, (value_n / 12));

cout << "With " << Frequency_at_A << " tuned at " << Note_Range << endl;

cout << "Your Note " << Frequency_of_A << " will be at " << Frequency_A << endl;

return 0;

}

int main() {

int note;

int nn; // Note Number

int o; // octnum

int f; // Frequency A

int d; // Note Difference

Note_Number:

cout << "Enter a note number between (1 and 12) ";

cout << "1: C" << endl;

cout << "2: C#" << endl;

cout << "3: D" << endl;

cout << "4: D#" << endl;

cout << "5: E" << endl;

cout << "6: F" << endl;

cout << "7: F#" << endl;

cout << "8: G" << endl;

cout << "9: G#" << endl;

cout << "10: A" << endl;

cout << "11: A#" << endl;

cout << "12: B" << endl;

cin >> note;

while (std::cin.fail()) {

cin.clear();

cin.ignore(numeric_limits::max(), ' ');

cout << "Enter a Numerics only for NOTE NUMBER: ";

goto Note_Number;

}

if ((note < 1) || (note > 12)) {

cout << "Input NOTE NUMBER OUT of Bound ";

cin.clear();

goto Note_Number;

}

switch (note) {

case 1: {

nn = 1;

break;

}

case 2: {

nn = 2;

break;

}

case 3: {

nn = 3;

break;

}

case 4: {

nn = 4;

break;

}

case 5: {

nn = 5;

break;

}

case 6: {

nn = 6;

break;

}

case 7: {

nn = 7;

break;

}

case 8: {

nn = 8;

break;

}

case 9: {

nn = 9;

break;

}

case 10: {

nn = 10;

break;

}

case 11: {

nn = 11;

break;

}

case 12: {

nn = 12;

break;

}

default: {

goto Note_Number;

break;

}

}

Octave_Number:

cout << "What octave are they in? " << endl;

cin >> o;

while (std::cin.fail()) {

cin.clear();

cin.ignore(numeric_limits::max(), ' ');

cout << "You can enter numerical value only for Octave for A: ";

goto Octave_Number;

}

if ((o < 1) || (o > 8)) {

cout << "The Octave Input for A is wrong ";

cin.clear();

goto Octave_Number;

}

Frequency_Number:

cout << "Enter frequency of A. (Range 416 to 465)" << endl;

cin >> f;

while (std::cin.fail()) {

cin.clear();

cin.ignore(numeric_limits::max(), ' ');

cout << "You can enter numerical value only for FREQUENCY for A: ";

goto Frequency_Number;

}

if ((f < 416) || (f > 465)) {

cout << "The Frequency Input for A is not correct ";

cin.clear();

goto Frequency_Number;

}

d = abs(nn - 10);

compute(f, d);

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

Students also viewed these Databases questions

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago