-4

im supposed to do this

Main Menu 
A – Arithmetic Series    
B – Geometric Series     
C – Harmonic Mean     
D – Geometric mean    
E - Taylor Polynomial of Degree n 
F – Largest Prime Number    
Enter your choice:

inside a box

my code is

#include <iostream>
#include <cfloat>

using namespace std;

int main(){
    string menu;

    cout<<"_._._._._._._._._._._._._._._._._._\n";
    cout<<"|            Main Menu              |\n";
    cout<<"|                                   |\n";
    cout<<"|A - Arithmetic Series              |\n";
    cout<<"|B - Geometric Series               |\n";
    cout<<"|C - Harmonic Mean                  |\n";
    cout<<"|D - Geometric Mean                 |\n";
    cout<<"|E - Taylor Polynomial of Degree n  |\n";
    cout<<"|F - Largest Prime Number           |\n";
    cout<<"|Enter your choice:\n";
    cin>> menu;
    cout<<"_._._._._._._._._._._._._._._._._._\n";


}

can someone help me out? i need to input a letter inside the box, but the box wont completely form because of the cin thingy

Bakri Bitar
  • 1,543
  • 18
  • 29
  • oh sorry, should i have had typed it instead? – Deric Jose Sep 19 '18 at 01:02
  • @DericJose just paste it in the question and format it. – Rick Sep 19 '18 at 01:03
  • oh okay thanks, in a sec – Deric Jose Sep 19 '18 at 01:03
  • Yes, all questions on stackoverflow.com must include all pertinent information in the question itself ***as plain text***. Suspicious links to dodgy external web sites can stop working at any time rendering the question meaningless. – Sam Varshavchik Sep 19 '18 at 01:04
  • How you do this depends entirely on the terminal emulator you are running your program in. Most people us a library like `ncurses` for this kind of thing. – Galik Sep 19 '18 at 01:06
  • Possible duplicate of [Move text cursor to particular screen coordinate?](https://stackoverflow.com/questions/10401724/move-text-cursor-to-particular-screen-coordinate) – Rishi Sep 19 '18 at 05:41

1 Answers1

2

When it reaches cin, the program stops and asks you for input. So just move cin after the output statements.

For exmaple, you can move the cin line to the bottom. Then you can see the whole box before the program asks you to input a value.

Is this what you want? enter image description here

#include <iostream>
#include <string>

using namespace std;

int main() {
    string menu;

    cout << "|_._._._._._._._._._._._._._._._._._|\n";
    cout << "|            Main Menu              |\n";
    cout << "|                                   |\n";
    cout << "|A - Arithmetic Series              |\n";
    cout << "|B - Geometric Series               |\n";
    cout << "|C - Harmonic Mean                  |\n";
    cout << "|D - Geometric Mean                 |\n";
    cout << "|E - Taylor Polynomial of Degree n  |\n";
    cout << "|F - Largest Prime Number           |\n";
    cout << "|_._._._._._._._._._._._._._._._._._|\n";
    cout << "Enter your choice:\n";
    cin >> menu;
}

Btw, you need to use #include <string> if you use string.


This enter image description here ?

Rick
  • 7,007
  • 2
  • 49
  • 79
  • Thanks! but now I can only input the value outside the box, is there a way i can input the value inside it? without breaking the box? – Deric Jose Sep 19 '18 at 01:13
  • @DericJose I don't understand. If you want to input inside the box, then the box won't complete before you input. – Rick Sep 19 '18 at 01:19
  • my prof wanted to have the "Enter your choice: (and the answer) " thing inside the box, is that even possible? edit: ok i just read your reply thanks!! – Deric Jose Sep 19 '18 at 01:19
  • @DericJose Then you should enter something as a input in your original program. See my answer after edited. – Rick Sep 19 '18 at 01:23
  • thank you sir! Ill use the 1st one that you showed since it looks way better – Deric Jose Sep 19 '18 at 01:29
  • 2
    Putting the prompt inside the box is *possible*, but not *easy* or *portable*. It would require you to output the entire box including the prompt, then MOVE THE INPUT CARET back to where you want after the prompt. There is no standard API in C++ to do that, though, but there are platform-specific terminal APIs that can. That is usually outside the scope of typical school courses, though. If your teacher wants this, he should have taught you how to do it. – Remy Lebeau Sep 19 '18 at 02:58