I was just wondering, can't i make a program that in the beginning ask me which program i want, something like i have a + Calculator and a - one, so how about if i can make a program that at the beginning says
"Choose the program you want:-
Addition = h
Subtraction = g
Enter the letter of your program:- ...."
Can that happen?
A way to combine programs...
Started by Unknown2dark, Apr 20 2007 12:13 AM
4 replies to this topic
#1
Posted 20 April 2007 - 12:13 AM
|
|
|
#2
Posted 20 April 2007 - 04:44 AM
What do you mean?
Do you want to make some kind of menu in your console application, or are you trying to start up other applications/processes?
Do you want to make some kind of menu in your console application, or are you trying to start up other applications/processes?
#3
Posted 20 April 2007 - 05:58 AM
Dunno the difference but, i just want when i open the program, instead of only having one function, it can be used for many functions, and that's done by a list in the beginning, is that easier to understand, or not?

#4
Posted 20 April 2007 - 07:17 AM
Hmm, I think you mean a menu. You've to give the user multiple choices of what to do, right? For example if it's a console-based calculator, you want to have the user to choice between addition, subtraction, etc.
A little example, using switch-statement.
An if-construction could had been used to.
A little example, using switch-statement.
An if-construction could had been used to.
#include <iostream>
void addition()
{
int a, b;
std::cout << "Input two numbers. " << std::endl;
std::cout << " Number 1: ";
std::cin >> a;
std::cout << " Number 2: ";
std::cin >> b;
std::cout << " Result: " << a+b << std::endl;
}
void subtraction()
{
int a, b;
std::cout << "Input two numbers. " << std::endl;
std::cout << " Number 1: ";
std::cin >> a;
std::cout << " Number 2: ";
std::cin >> b;
std::cout << " Result: " << a-b << std::endl;
}
int main()
{
char choice = 0;
while(choice != 'Q')
{
std::cout << std::endl;
std::cout << " ---- " << std::endl;
std::cout << std::endl;
std::cout << "What do you want to do?" << std::endl;
std::cout << " 1. Addition" << std::endl;
std::cout << " 2. Subtraction" << std::endl;
std::cout << " Q. Exit" << std::endl;
std::cout << ">> ";
std::cin >> choice;
switch(choice)
{
case '1':
addition();
break;
case '2':
subtraction();
break;
case 'Q':
break;
default:
std::cout << "Invalid option, try again!" << std::endl;
break;
}
}
return 0;
}
Tell me if that weren't what you meant.
#5
Posted 20 April 2007 - 02:11 PM
That was just what i want, really many thanks, i will try to figure out how to make my own now, thanks btw, you've been a great help since i joined..



Sign In
Create Account


Back to top









