Click here to Skip to main content
15,922,166 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Is an STL vector an array? Pin
Tim Smith12-Jul-03 6:22
Tim Smith12-Jul-03 6:22 
AnswerRe: Is an STL vector an array? Pin
realfly11-Jul-03 21:38
realfly11-Jul-03 21:38 
GeneralRe: Is an STL vector an array? Pin
DaveE9th12-Jul-03 2:12
DaveE9th12-Jul-03 2:12 
Generali am very confused please help me! i am chinese ,my english is very poor, i had troubled with a question in MFC Pin
hongge11-Jul-03 20:13
hongge11-Jul-03 20:13 
Generalsomething like that8) Pin
realfly11-Jul-03 21:35
realfly11-Jul-03 21:35 
GeneralRe: something like that8) Pin
hongge11-Jul-03 23:15
hongge11-Jul-03 23:15 
GeneralRe: something like that8) Pin
realfly13-Jul-03 15:40
realfly13-Jul-03 15:40 
GeneralNeed some help(Beginner) Pin
Fightingbee11-Jul-03 19:43
Fightingbee11-Jul-03 19:43 
Ok here is the goal of the program:
Create a C++ Program that acts as a calculator for the user. The program should start off by printing, to the screen, a menu that offers the user one of five options. The menu should look somethings like this, but feel free to dress it up any way you want to make it look nice.
1.Add
2.Subtract
3.Multiply
4.Divide
5.Exit

The user wil then select one of the options. Then the program must prompt the user forthe input data and print the results to the screen. After the user has found the desired results, the menu should then reappear to allow the user to do another calculation. Do not let the user out of the program until the user has typed 5 for exit.

Rules: The program must use at least 5 functions, not including MAIN.One funtion will be for the menu and one function for each of the calculations.

Input for the program will be data that is in the integer range, and you can make the assumption that I will NOT type 0 to force a divide by 0 error ( Nice instructor eh?? . However, if the user types in a menu item number that does not appear, then the program should return the user an error message that they have typed an incorrect number and allow the user to retype a valid number.


Ok with all that said below is the source code that I have written in MS Visual C++. I am thinking I am running into problems with my functions, although I am not to sure. And thanks in advance for anyone who takes the time to offer some help.



#include <iostream>
#include <conio.h>

using namespace std;


int sum = 0;
int ssum = 0;
int msum = 0;
double dsum = 0;
int x = 0;
int y = 0;
int menu();
int c = menu();

int main()
{	
	do
	{
		int menu();

		if(c == 1)
		   int add();
		else if(c == 2)	
	       	   int sub();
		else if(c == 3)
		   int multi();
		else if(c == 4)
		   double div();
	}

	getch();
	return 0;
}
		 
int menu()
{	
	int sel = 0;

    cout<<"Please select a menu choice..."<<endl
    <<"1. Add"<<endl
    <<"2. Subtract"<<endl
    <<"3. Multiply"<<endl
    <<"4. Divide"<<endl
    <<"5. Exit program"<<endl;
		cin>>sel;
		
	if(c = 5)
	    cout<<"Thank you for using the calculator!"<<endl;
	else if(c > 5 && c < 1)
	    cout<<"You have entered an invalid selection!"<<endl;

	return sel;
}

int add()
{
        cout<<"Please enter a number..."<<endl;
		cin>> x;
	cout<<"Please enter your second number..."<<endl;
		cin>>y;

	sum = x + y;
	cout<<"The answer is "<<sum<<endl;

	    return sum;
}

int sub()
{
        cout<<"Please enter a number..."<<endl;
		cin>> x;
	cout<<"Please enter your second number..."<<endl;
		cin>>y;
	
	ssum = x - y;
	cout<<"The answer is "<<ssum<<endl;

	    return ssum;
}

int multi()
{
	cout<<"Please enter a number..."<<endl;
		cin>> x;
	cout<<"Please enter your second number..."<<endl;
		cin>>y;
	
	msum = x * y;
	cout<<"The answer is "<<msum<<endl;

		return msum;
}

double div()
{
	cout<<"Please enter a number..."<<endl;
		cin>> x;
	cout<<"Please enter your second number..."<<endl;
		cin>>y;
	
	dsum = x / y;
	cout<<"The answer is "<<dsum<<endl;

		return dsum;
}



*Edit* Hopefully this helps now Wink | ;)
GeneralRe: Need some help(Beginner) Pin
Michael Dunn11-Jul-03 20:09
sitebuilderMichael Dunn11-Jul-03 20:09 
GeneralRe: Need some help(Beginner) Pin
Fightingbee11-Jul-03 20:21
Fightingbee11-Jul-03 20:21 
GeneralRe: Need some help(Beginner) Pin
Michael P Butler11-Jul-03 21:43
Michael P Butler11-Jul-03 21:43 
GeneralRe: Need some help(Beginner) Pin
Fightingbee12-Jul-03 5:54
Fightingbee12-Jul-03 5:54 
GeneralRe: Need some help(Beginner) Pin
Snyp12-Jul-03 6:33
Snyp12-Jul-03 6:33 
GeneralChanging Font Pin
Kristian Kratzenstein11-Jul-03 19:39
Kristian Kratzenstein11-Jul-03 19:39 
GeneralRe: Changing Font Pin
hongge11-Jul-03 20:29
hongge11-Jul-03 20:29 
GeneralRe: Changing Font Pin
Kristian Kratzenstein11-Jul-03 21:10
Kristian Kratzenstein11-Jul-03 21:10 
GeneralRe: Changing Font Pin
pranavamhari11-Jul-03 22:35
pranavamhari11-Jul-03 22:35 
GeneralRe: Changing Font Pin
Kristian Kratzenstein12-Jul-03 6:21
Kristian Kratzenstein12-Jul-03 6:21 
GeneralOn Un-minimizing information stored in array is not shown. Pin
Terry Eff11-Jul-03 19:04
Terry Eff11-Jul-03 19:04 
Questionhow text can display in spiral form Pin
Member 47204511-Jul-03 15:01
Member 47204511-Jul-03 15:01 
AnswerRe: how text can display in spiral form Pin
Anthony_Yio15-Jul-03 1:23
Anthony_Yio15-Jul-03 1:23 
AnswerRe: how text can display in spiral form Pin
Anthony_Yio15-Jul-03 1:23
Anthony_Yio15-Jul-03 1:23 
Questionwhat is the different between the DLL and application Pin
gdzfy11-Jul-03 14:33
gdzfy11-Jul-03 14:33 
AnswerRe: what is the different between the DLL and application Pin
gdzfy11-Jul-03 14:34
gdzfy11-Jul-03 14:34 
GeneralRe: what is the different between the DLL and application Pin
John M. Drescher11-Jul-03 17:49
John M. Drescher11-Jul-03 17:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.