0

Is it possible display an input message as follows?

Enter First Fraction:_/_
Enter Second Fraction: _/_

Where _ are Input spaces?

Using some sort of the following code??

cout<<"Enter First Fraction: ";
cin>>N1>>"/">>D1;
cout<<"Enter Second Fraction: ";
cin>>N2>>"/">>D2;

OR

cout<<"Enter First Fraction: ";
cin>>N1>>/>>D1;
cout<<"Enter Second Fraction: ";
cin>>N2>>/>>D2;
Genious28
  • 11
  • 9
  • 1
    no you cannot do that. You need advanced interaction with your terminal to do something like that. I bet `ncurses` can do it – 463035818_is_not_an_ai Oct 30 '20 at 15:53
  • ncurses? what's that? – Genious28 Oct 30 '20 at 15:54
  • I saw this code in another Stack Question.. ``` char plus{},img{}; double x{},y{}; cin>> x >> plus >> y >> img; if (plus!='+' || img!='i') cout << "\nError: "<< "x=" << x <<", plus=" << plus <<", y=" << y <<", img=" << img; else cout << "\nComplex: " << x << plus << y << img; return 0;``` It seems to require the user to enter a '+' in the middle and a '!' in the end... but i tried, it still doesn't work. – Genious28 Oct 30 '20 at 15:56
  • ouh, tabs disappeared in comments. :/ – Genious28 Oct 30 '20 at 15:57
  • lemme put that code as a suggested answer.. – Genious28 Oct 30 '20 at 15:57
  • code in comments is not readable. If you have a question about code you should post the code in the question – 463035818_is_not_an_ai Oct 30 '20 at 15:57
  • i added the answer i found in another stack question here.. as a suggested answer. – Genious28 Oct 30 '20 at 15:58
  • if that is the answer then your question is very unclear. When you write "Is it possible display an input message as follows?" then I understand it as if the following two lines should appear on the screen before the user enters something – 463035818_is_not_an_ai Oct 30 '20 at 16:34
  • Well, it's not possible to do that with C++ in Console. And obviously, i can't make it appear step by step like in PowerPoint Presentations. StackOverFlow Developers should probably add this feature. Anyway, sorry for the inconvenience and confusions. – Genious28 Oct 30 '20 at 16:41
  • anything is possible. Seriously, it can be done, just not easily. – 463035818_is_not_an_ai Oct 30 '20 at 16:42
  • Yeah, but it would be REALLY lengthy and would use statements that the book hasn't taught in the first 2 chapters. – Genious28 Oct 31 '20 at 09:40

1 Answers1

0

Here is the Solution to my problem just in case anyone else is facing it.. Credits go to @qPCR4vir

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

using namespace std;

main()
{   //This program encourages the user to perform a sum of two fractions.
    int N1, D1, N2, D2, N, D;
    char divide{};
    system("cls");

    cout<<"The Format is: 'A/B' & 'C/D'..\n\n";
    cout<<"Enter First Fraction: ";
    cin>>N1>>divide>>D1;
    cout<<"Enter Second Fraction: ";
    cin>>N2>>divide>>D2;
    
    if (divide=='/')
    {
        N=(N1*D2)+(D1*N2);  //Numerator
        D=D1*D2;            //Denominator
        cout<<"Sum of Both Fractions is: "<<N<<"/"<<D;
    }
    else
    {
        system("cls");
        cout<<"The Correct Format is: A/B & C/D\nWhere these alphabets are Integers..\n\n";
        cout<<"Example: 4/5";
    }

    getch();
    system("cls");
    return(0);
}

Here's the Part of code that Specifies the Format ONLY for 'cin' Statement.

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

using namespace std;

int main() 
{
    char divide{};                  //iota{};
    int x{},y{};
    
    cout<<"Enter Dividion of Two Numbers (A/B): ";
    cin>>x>>divide>>y;              //>> iota;
                
    if (divide=='/')                //&& iota=='i') 
    {
                                    //x=(N1*D2)+(D1*N2);    //Numerator
                                    //y=D1*D2;              //Denominator
        cout<<"The Fractional Form is: "<<x<<"/"<<y;
    }
    else
    {
        system("cls");
        cout<<"The Correct Format is: A/B & C/D\nWhere these alphabets are Integers..\n\n";
        cout<<"Example: 4/5";
    }


    getch();
    return 0;
}

Note: This is Simplified/Modified Solution of @qPCR4vir at; Reading in a specific format with cin

Genious28
  • 11
  • 9