[Attempt] C++ Equation solver menu

User Tag List

Results 1 to 2 of 2
  1. #1
    Xel's Avatar ★ Elder ★
    Authenticator enabled
    Reputation
    1179
    Join Date
    Jul 2008
    Posts
    2,906
    Thanks G/R
    94/51
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Attempt] C++ Equation solver

    YES I am a beginner.
    So, I didn't even try to use any switches or cases in this program.
    So it's plain if, cout, cin....

    The important point in my program is that it works.
    YES I know that this is as easy as C++ gets.

    Code:
    #include <iostream>
    #include <windows.h>
    #include <stdlib.h>
    
    using namespace std;
    
    double i;
    double a;
    double b; 
    double c;
    double result1;
    double result2;
    double choise=1;
    
    int main()
    {
    while (choise!=0)
    {
          
    system ("cls"); 
    system ("color 0A");
    SetConsoleTitle("Equation solver"); 
    
    cout << "[Equation solver]\n";
    cout << "ax+b=c\n\n";
    cout << "[Values]\n";
    cout << "a=";
    cin >> a;
    cout << "b=";
    cin >> b;
    cout << "c=";
    cin >> c;
    
    cout << "\n[Calculation]\n";
    
    if (a==0)
    {
    cout << "Error #1! Don't set a as a zero (a!=0)!";
    }
    
    if (b>0 && a!=0 || b==0 && a!=0)
    {
    cout << a << "x+" << b << "=" << c << endl;
    cout << a << "x=" << c << "-" << b << endl;
    cout << a << "x=" << c-b << "|:" << a << endl; 
    cout << "x=" << (c-b)/a;
    }
    
    if (b<0 && a!=0)
    {
    cout << a << "x" << b << "=" << c << endl;
    cout << a << "x=" << c << b << endl;
    cout << a << "x=" << c-b << "|:" << a << endl; 
    cout << "x=" << (c-b)/a;
    }
    
    //Exit function//
    cout << "\n\n[Continue]\nPress 1 to continue and 0 to exit: ";
    cin >> choise;
    
    }
    
    }
    This is how it works:
    Code:
    [Equation solver]
    ax+b=c
    
    [Values]
    a=1
    b=-2
    c=3
    
    [Calculation]
    1x-2=3
    1x=3+2
    1x=5 |:1
    x=5
    
    [Continue]
    Press 1 to continue and 0 to exit:
    PS: I also have quadratic equation solver on my other computer,
    just PM me if want it posted here (lazy on math, huh?).
    Last edited by Xel; 12-14-2009 at 11:40 AM.

    [Attempt] C++ Equation solver
  2. #2
    dwarfhitman's Avatar Member
    Reputation
    13
    Join Date
    Aug 2007
    Posts
    13
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you use else if statements you wont have to keep checking to make sure a!=0. It will make your code a lot more readable.

Similar Threads

  1. [Program] Algebrator - Math Equation Solver
    By SunnyKatt in forum Community Chat
    Replies: 3
    Last Post: 10-30-2009, 02:41 PM
  2. First Attempt
    By Fault in forum Art & Graphic Design
    Replies: 6
    Last Post: 06-05-2007, 02:37 PM
  3. Double boss attempt for loot
    By rudez in forum World of Warcraft Exploits
    Replies: 7
    Last Post: 11-02-2006, 06:53 AM
  4. a first attempt
    By MechaAngelus in forum WoW ME Questions and Requests
    Replies: 10
    Last Post: 08-21-2006, 03:30 PM
  5. a first attempt
    By MechaAngelus in forum World of Warcraft Model Editing
    Replies: 3
    Last Post: 08-17-2006, 03:13 PM
All times are GMT -5. The time now is 08:02 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search