Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Software Development
Tag Cloud
access acer asus bios bsod computer crash desktop dns driver drivers error ethernet excel freeze gaming graphics hard drive hardware hdmi internet laptop malware memory monitor motherboard network printer problem ram registry repair router slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Software & Hardware > Software Development >
structured programming

Reply  
Thread Tools
n00bsmith's Avatar
Junior Member with 11 posts.
 
Join Date: Sep 2009
Experience: Beginner
22-Nov-2009, 04:33 AM #1
structured programming
/** Guitar Scales Program
* I have been writing this program and as it has grown I wanted to
* make it more organized thus I learned about structured programming
* but I am having some trouble.I think that I have found a way that
* works. I can get the first two menus to load (select_scale &
* select_key) however as soon as they pass the int values to
* "open_scale" there is an error it must be in the way I send the
* variable data but I am not sure why or how to fix it I get no specific
* errors such as " missing ';' " there is a memory error instead I don't
* wish to post all of it (using visual studio by the way).
*
* This program presents two different menus to select a musical scale
* and then key
* (select_scale, select_key).
*
* *The rest of the code is located in open_scale.* *
* After which it searches the appropriate .txt file
* (ifstream open and seek).
* and inputs the values to an array.
* ( x[11] ).
* Then a simple 'cout' and a little display structure is all that is needed to
* output a mock-up of a guitar fretboard.
*
* Thank you in advanced for any help!
*/


#include <iostream>
#include <windows.h> //console design ex:SetConsoleTitle
#include <fstream> //if and ofstream gets txt content
#include <string> //duh

using namespace std;
int select_key_menu(void);
int select_scale_menu(void);
void open_scale(int, int);

int main()
{
SetConsoleTitle ("Guitar Scales");
int k;
int s;
//do{
s = select_scale_menu();
k = select_key_menu();
open_scale(s, k);
return 0;
//while(input_key value != 'Q' or 'q'...maybe 0 instead int not char)
}


int select_scale_menu()
{
int scale = 0;

cout << endl << "Featured Scales: \n\n"
<< "\t1. Major Scale \n"
<< "\t2. Minor Scale \n"
<< endl << "Select scale number: ";
cin >> scale;
cout << endl;
return scale;
}


int select_key_menu()
{
int key = 0;


cout << endl << "Keys: \n\n"
<< "\t 1. All"<<endl
<< "\t 2. Ab" << endl
<< "\t 3. A" << endl
<< "\t 4. Bb" << endl
<< "\t 5. B" << endl
<< "\t 6. C" << endl
<< "\t 7. Db" << endl
<< "\t 8. D" << endl
<< "\t 9. Eb" << endl
<< "\t10. E" << endl
<< "\t11. F" << endl
<< "\t12. Gb" << endl
<< "\t13. G" << endl
<< endl << "Select key number: ";
cin >> key;
return key;
}

void open_scale(int scale, int key)
{
ifstream inFile;
char notout;
string x[11];
string gs(" |--");
string gm("-|--");
string ge("-|\n");

switch(scale) {
case 1:
inFile.open("T:\\projects\\code\\major.txt");
break;
case 2:
inFile.open("T:\\projects\\code\\minor.txt");
break;
default: cout << "Error incorrect selection type\n";
}



switch(key) {
case 1:
inFile.seekg(0, ios::beg);
break;
case 2:
inFile.seekg(36, ios::beg);
break;
case 3:
inFile.seekg(72, ios::beg);
break;
case 4:
inFile.seekg(110, ios::beg);
break;
case 5:
inFile.seekg(146, ios::beg);
break;
case 6:
inFile.seekg(185, ios::beg);
break;
case 7:
inFile.seekg(221, ios::beg);
break;
case 8:
inFile.seekg(261, ios::beg);
break;
case 9:
inFile.seekg(296, ios::beg);
break;
case 10:
inFile.seekg(333, ios::beg);
break;
case 11:
inFile.seekg(369, ios::beg);
break;
case 12:
inFile.seekg(405, ios::beg);
break;
case 13:
inFile.seekg(443, ios::beg);
break;
default: cout << "Error incorrect selection type\n";

}

if (!inFile) {
cout << "Unable to open file\n";
cin >> notout;
exit(1); // terminate with error
}
else {
inFile >> x[0] // Ab
>> x[1] // A
>> x[2] // Bb
>> x[3] // B
>> x[4] // C
>> x[5] // Db
>> x[6] // D
>> x[7] // Eb
>> x[8] // E
>> x[9] // F
>> x[10]; // Gb
//>> x[11]; // G < IF I COMMENT THIS OUT EVERYTHING IS FINE??
inFile.close();
}


cout
<< endl << endl
/* E */ << x[8]
<< gs << x[9] << gm << x[10] << gm << x[11] << gm << x[0]
<< gm << x[1] << gm << x[2] << gm << x[3] << gm << x[4]
<< gm << x[5] << gm << x[6] << gm << x[7] << gm << x[8]
<< ge

/* A */ << x[3]
<< gs << x[4] << gm << x[5] << gm << x[6] << gm << x[7]
<< gm << x[8] << gm << x[9] << gm << x[10] << gm << x[11]
<< gm << x[0] << gm << x[1] << gm << x[2] << gm << x[3]
<< ge

/* D */ << x[11]
<< gs << x[0] << gm << x[1] << gm << x[2] << gm << x[3]
<< gm << x[4] << gm << x[5] << gm << x[6] << gm << x[7]
<< gm << x[8] << gm << x[9] << gm << x[10] << gm << x[11]
<< ge

/* G */ << x[6]
<< gs << x[7] << gm << x[8] << gm << x[9] << gm << x[10]
<< gm << x[11] << gm << x[0] << gm << x[1] << gm << x[2]
<< gm << x[3] << gm << x[4] << gm << x[5] << gm << x[6]
<< ge

/* B */ << x[1]
<< gs << x[2] << gm << x[3] << gm << x[4] << gm << x[5]
<< gm << x[6] << gm << x[7] << gm << x[8] << gm << x[9]
<< gm << x[10] << gm << x[11] << gm << x[0] << gm << x[1]
<< ge

/* E */ << x[8]
<< gs << x[9] << gm << x[10] << gm << x[11] << gm << x[0]
<< gm << x[1] << gm << x[2] << gm << x[3] << gm << x[4]
<< gm << x[5] << gm << x[6] << gm << x[7] << gm << x[8]
<< ge
<< endl << endl;


cout << "EXIT: ";
cin >> notout;

}

Last edited by n00bsmith; 22-Nov-2009 at 09:17 AM..
IMM's Avatar
IMM IMM is offline IMM is authorized to help remove malware.
Malware Removal Specialist with 3,260 posts.
 
Join Date: Feb 2002
22-Nov-2009, 07:08 AM #2
Why do you have return 0; before open_scale(s, k); ?
n00bsmith's Avatar
Junior Member with 11 posts.
 
Join Date: Sep 2009
Experience: Beginner
22-Nov-2009, 07:27 AM #3
oh
There changed it I have been updating the code a little bit on this post added that in the wrong spot.
n00bsmith's Avatar
Junior Member with 11 posts.
 
Join Date: Sep 2009
Experience: Beginner
22-Nov-2009, 09:10 AM #4
there seems to be a problem with x[11] when I remove it the program works fine minus the last note of the scale of course. Why is this?
n00bsmith's Avatar
Junior Member with 11 posts.
 
Join Date: Sep 2009
Experience: Beginner
22-Nov-2009, 09:27 AM #5
ha
wow I just need to make it x[12] instead of x[11] I need some sleep. Well hope you all enjoyed me answering my own question.
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 09:16 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.