I'd like to write a console program that will allow me to select options (1, 2, 3), then select another set of options (1, 2, 3). Then output a concatenated string of the two selected to a DOS prompt.
Where I am struggling is how to store the values/options in the C++ application, do I store it as an array? struct?
Example of what I want stored
First set of options
1) Desktop
2) Laptop
3) Server
Second set of options
1) Keyboard
2) Mouse
3) Lightpen
Possible output combinations
desktop_keyboard
laptop_keyboard
server_mouse
server_lightpen
etc
Any help is appreciated, been banging my head against the desk for a few days now.
I don't see any reason, really to store the options at all. I would personally use a switch to determine the first set, and add the chosen value to an empty string, followed by an underscore, then have another switch to determine the second set, and add the chosen value to the end of the same string.
Thank you very much. I was having a syntax error when I was trying to declare my string in my case statement, apparently I had to enclose it in {} and then it worked.
This line
{string sMachineType = "desktops_";
cout << sMachineType;}
This is the code below
int main()
{
int machinetypeinput;
cout<<"1. Desktops\n";
cout<<"2. Laptops\n";
cout<<"3. Servers\n";
cout<<"4. Exit\n";
cout<<"Selection: ";
cin>> machinetypeinput;
switch ( machinetypeinput ) {
case 1: // Note the colon, not a semicolon
//desktops1();
{string sMachineType = "desktops_";
cout << sMachineType;}
break;
The problem I am having now is getting my variables that I set in the case statements out into other parts of the program so I can COUT them.
Here is the source as it stands now
#include <iostream>
//#include <cstdio>
#include <cstdlib>
#include <string>
using namespace std;
int main()
{
int machinetypeinput;
cout<<"1. Desktops\n";
cout<<"2. Laptops\n";
cout<<"3. Servers\n";
cout<<"4. Exit\n";
cout<<"Selection: ";
cin>> machinetypeinput;
string sMachineType;
switch ( machinetypeinput ) {
case 1: // Note the colon, not a semicolon
//desktops1();
{string sMachineType = "desktops_";
cout << sMachineType;}
break;
case 2: // Note the colon, not a semicolon
//laptops1();
{string sMachineType = "laptops_";
cout << sMachineType;}
break;
case 3: // Note the colon, not a semicolon
//servers1();
{string sMachineType = "servers_";
cout << sMachineType;}
break;
case 4: // Note the colon, not a semicolon
cout<<"Exit!\n";
break;
default: // Note the colon, not a semicolon
cout<<"Error, bad input, quitting\n";
break;
}
// This will determine the accessory
int accessoryinput;
cout<<"1. Keyboard\n";
cout<<"2. Mouse\n";
cout<<"3. Lightpen\n";
cout<<"4. Exit\n";
cout<<"Selection: ";
cin>> accessoryinput;
string sAccessoryType;
switch ( accessoryinput ) {
case 1: // Note the colon, not a semicolon
//sMachineType += "Keyboard";
{string sAccessoryType = "keyboard_";
cout << sMachineType << sAccessoryType << endl;}
//cout << sMachineType += sAccessoryType;}
//sMachineType = sMachineType << "keyboardtest";
//cout << sMachineType << endl;
break;
/*
case 2: // Note the colon, not a semicolon
{string sAccessoryType = "mouse_";
cout << sAccessoryType;}
break;
case 3: // Note the colon, not a semicolon
{string sAccessoryType = "lightpen_";
cout << sAccessoryType;}
break;
case 4: // Note the colon, not a semicolon
cout<<"Exit!\n";
break;
*/
default: // Note the colon, not a semicolon
cout<<"Error, bad input, quitting\n";
break;
}
cout << "blah" << sMachineType << endl;
system("PAUSE");
//cout << sMachineType << sAccessoryType;
//cin.get();