c++ - Switch menu calculator will not display arithmetic -



c++ - Switch menu calculator will not display arithmetic -

sorry if title confusing, did not know how word issue well. understand of programme not finished of right now, i'm working on keyboard input sections.

basically, have create programme allows user either input file set integers or have user come in 2 integers of own. user asked arithmetic performed on integers. created menu , sub menus using switch statement allow user navigate destination.

my problem is, when seek utilize input through keyboard option, programme fails display calculated variable. can navigate alternative , input integers when programme displays final reply states: "the total is: menu" , kicks me main menu.

my specific example: user selects (2) keyboard input. user selects (1) add-on arithmetic user enters integer (1) user enters integer (2) programme displays "the total is: menu" programme loops main menu.

here code:

#include "complx.h" #include <iostream> using namespace std; ifstream infile ("in.dat"); int main() { int choiceone, choiceonesubmenu, choicetwosubmenu, digitone, digittwo, digittotal; bool menu = true; do{ cout << "menu \n"; cout << "=========== \n"; cout << "(1) input file \n"; cout << "(2) input keyboard \n"; cout << "(3) exit programme \n"; cout << "enter numerical selection: \n"; cin >> choiceone; switch (choiceone) { case 1: cout << "you chose input file \n"; cout << "=============== \n"; cout << "which arithmetic applied? \n"; cout << "(1) add-on + \n"; cout << "(2) subtraction - \n"; cout << "(3) multiplication * \n"; cout << "(4) partition / \n"; cout << "enter numerical selection: \n"; cin >> choiceonesubmenu; switch (choiceonesubmenu) { case 1: break; case 2: break; case 3: break; case 4: break; } break; case 2: cout << "you chose input keyboard \n"; cout << "=============== \n"; cout << "which arithmetic applied? \n"; cout << "(1) add-on + \n"; cout << "(2) subtraction - \n"; cout << "(3) multiplication * \n"; cout << "(4) partition / \n"; cout << "enter numerical selection: \n"; cin >> choicetwosubmenu; switch (choicetwosubmenu) { case 1: cout << "you chose add-on \n"; cout << "=============== \n"; cout << "enter first integer: \n"; cin >> digitone; cout << "enter sec integer: \n"; cin >> digittwo; digittotal = (digitone + digittwo); cout << "the total is: " + digittotal; break; case 2: cout << "you chose subtraction \n"; cout << "=============== \n"; cout << "enter first integer: \n"; cin >> digitone; cout << "enter sec integer: \n"; cin >> digittwo; digittotal = (digitone - digittwo); cout << "the total is: " + digittotal; break; case 3: cout << "you chose multiplication \n"; cout << "=============== \n"; cout << "enter first integer: \n"; cin >> digitone; cout << "enter sec integer: \n"; cin >> digittwo; digittotal = (digitone * digittwo); cout << "the total is: " + digittotal; break; case 4: cout << "you chose partition \n"; cout << "=============== \n"; cout << "enter first integer: \n"; cin >> digitone; cout << "enter sec integer: \n"; cin >> digittwo; digittotal = (digitone / digittwo); cout << "the total is: " + digittotal; break; } break; case 3: cout << "you have chosen exit"; } }while(choiceone!=3); }

cout << "the total is: " + digittotal;

you can't convert digit string , concatenate using + operator.

edit: can this:

cout << "the total is: " << itoa(digittotal);

or these

c++ menu switch-statement

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -