Thread: decision program ??

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    3

    decision program ??

    Code:
    #include <iostream>
    #include <string>
    
    
    using namespace std;
    
    int main(void)
    {
        string name;
       string math;
       ;int a;
       ;int d;
       ;int matha;
       
       ;cout << "Enter name: \n"
        ;cin >> name;
        
       ;cout << "Enter math grade " << name << " got: \n"
       ;cin >> math;
       if (matha = a){cout << name << " passed \n"; }
       else 
       if (matha = d){cout << name << " failed \n";}
       ;system("PAUSE");
        return 0;
    }
    Last edited by hiphop; 02-05-2009 at 12:28 PM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Moved to C++ programming forum.

    One possible problem is because you are assigning (matha = a) instead of comparing for equality (matha == a).

    Oh, and kindly indent your code more consistently and get rid of those superfluous empty statements.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    3
    Quote Originally Posted by laserlight View Post
    Moved to C++ programming forum.

    One possible problem is because you are assigning (matha = a) instead of comparing for equality (matha == a).

    Oh, and kindly indent your code more consistently and get rid of those superfluous empty statements.
    okay but its for C not C++ and please explain what you mean by indentting my code??
    *edit* Ive placed two == but now it doesnt state whether its a pass or fail it completely ignores that ???
    Last edited by hiphop; 02-05-2009 at 12:32 PM.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    please explain what you mean by indentting my code??
    Well, you are nearly there, but a little more consistency is good. For example:
    Code:
    #include <iostream>
    #include <string>
    #include <cstdlib>
    
    using namespace std;
    
    int main()
    {
        string name;
        string math;
        int a;
        int d;
        int matha;
    
        cout << "Enter name: \n";
        cin >> name;
    
        cout << "Enter math grade " << name << " got: \n";
        cin >> math;
        if (matha = a)
        {
            cout << name << " passed \n";
        }
        else if (matha = d)
        {
            cout << name << " failed \n";
        }
    
        system("PAUSE");
        return 0;
    }
    I took the liberty of removing the superfluous empty statements as including <cstdlib> which is needed for system() (which you do not need to use in the first place), but I did not make the fixes I suggested.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Feb 2009
    Posts
    3
    Quote Originally Posted by laserlight View Post
    Well, you are nearly there, but a little more consistency is good. For example:
    Code:
    #include <iostream>
    #include <string>
    #include <cstdlib>
    
    using namespace std;
    
    int main()
    {
        string name;
        string math;
        int a;
        int d;
        int matha;
    
        cout << "Enter name: \n";
        cin >> name;
    
        cout << "Enter math grade " << name << " got: \n";
        cin >> math;
        if (matha = a)
        {
            cout << name << " passed \n";
        }
        else if (matha = d)
        {
            cout << name << " failed \n";
        }
    
        system("PAUSE");
        return 0;
    }
    I took the liberty of removing the superfluous empty statements as including <cstdlib> which is needed for system() (which you do not need to use in the first place), but I did not make the fixes I suggested.
    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

Tags for this Thread