Take a look at my program(math problem)

This is a discussion on Take a look at my program(math problem) within the C++ Programming forums, part of the General Programming Boards category; #include <iostream> #include <conio.h> #include <conio.c> #define SHOREHIGH "Welcome to Shore High School!! " typedef char ZOO: typedef int USHORT; ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    106

    Take a look at my program(math problem)

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

    #define SHOREHIGH "Welcome to Shore High School!! "

    typedef char ZOO:
    typedef int USHORT;

    USHORT useranswer;

    int main()
    {
    USHORT classrooms(20);
    USHORT teachers=2*20;
    textcolor(9);
    textbackround(7);
    cout << SHOREHIGH;
    cout << "\nHeres a math problem. There are 20 classrooms, 500 students in the entire school, and 2 teachers per classroom. How many teachers are there in the entire school?";
    cin >> useranswer;

    if (useranswer==teachers) {
    cout << "\nYou're absolutely correct"; }

    if (useranswer!=teachers) {
    cout << "\nWRONG!! Try again\n"; }

    getch();
    return 0;
    }

    Have a better method of making this program?

  2. #2
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330
    *Don't use unneccessary #definitions
    *Don't use unneccessary typedefs
    *Don't use variables when variables aren't needed

    Code:
    #include <iostream.h>
    #include <conio.h>
    
    int main()
    {
    	short userans;
    
    	cout << "Welcome to Shore High School!!";
    	cout << "\nHeres a math problem. There are 20 classrooms, 500 students in the entire \nschool, and 2 teachers per classroom. How many teachers are there in the\nentire school ?"; 
    	cin >> userans;
    
    	if (userans == 40) 
    		cout << "\nYou're absolutely correct"; 
    	else  
    		cout << "\nWRONG!! Try again\n"; 
    
    	getch();
    
    	return 0;
    }

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    12

    just a little shorter

    #include <iostream>
    using namespace std;
    #include <conio.h>

    int main()
    {
    short userans;

    cout << "Welcome to Shore High School!!";
    cout << "\nHeres a math problem. There are 20 classrooms, 500 students in the entire \nschool, and 2 teachers per classroom. How many teachers are there in the\nentire school ?";
    cin >> userans;
    (userans == 40) ? cout<<"U R right" : cout<<"U R wrong";

    getch();
    return 0;
    }


    Even the greatest of whale is helpless, in the middle of the dessert.
    So help someone who needs help today then some one else will help U tommorrow when U need it.

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    *dont include *.c files

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 05:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 09:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21