.NETGURU
Problems with a program
Messages   Related Types
This message was discovered on microsoft.public.dotnet.academic.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Johnny Lange (VIP)
I'm writing a program in Visual C++ .Net that ask's the user to enter two
mumbers, obtains the two numbers from the user and prints the sum, product,
difference, and quotient of the two numbers. The problem is I can get the sum
to print, but not product, diffrence, and quotients to print their results.
Any help would be great!
Reply to this message...
 
    
Peter van der Goes
"Johnny Lange" <Johnny Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

It sounds like a short program, so could you post your code so we can offer
meaningful suggestions?
Your problems could be caused by any number of things in the code.

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.

Reply to this message...
 
    
Johnny Lange (VIP)
Thanks for the reply. It was a code exercise from a book, however I decided
that the book didn't really explain well for beginners so I exchanged it for
a much better one ;-) Anyway here's the source code:

//This is the main project file for VC++ application project
// generated using an Application Wizard.

#include "stdafx.h"

#using <mscorlib.dll>

using namespace System;

int _tmain()
{
String *num1,
     *num2,
     *sum,
         *product,
         *diffrence,
         *quotient;

    Console::WriteLine(S"Enter in the first number");
    num1 = Int32::Parse( Console::ReadLine() );

    Console::WriteLine(S"Enter in the second number");
    num2 = Int32::Parse( Console::ReadLine() );

    sum = num1 + num2;
    product = num1 * num2;
    diffrence = num1 - num2;
    quotient = num1 / num2;

    Console::WriteLine( S"\nThe sum is ", sum->ToString() );
    Console::WriteLine( S"\nThe product is ", product->ToString() );
    Console::WriteLine( S"\nThe diffrence is ", diffrence->ToString() );
    Console::WriteLine( S"\nThe quotient is ", quotient->ToString() );

    return 0;
}

//End of program source code.

"Peter van der Goes" wrote:

[Original message clipped]

Reply to this message...
 
    
Peter van der Goes
"Johnny Lange" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
> Thanks for the reply. It was a code exercise from a book, however I
decided
> that the book didn't really explain well for beginners so I exchanged it
for
[Original message clipped]

When you say the sum is displayed, is it displayed as the actual sum, or as
the concatenation of the two input numbers?
When I attempt to compile your code, I get errors such as:
"error C2440 '=': cannot convert from 'int' to 'System::String__gc*'"
at the line:

num1 = Int32::Parse( Console::ReadLine() );

which is exactly what I would expect. You need to use the correct numeric
variable types for the data. IOW, num1 and num2 need to be ints, if that is
the requirement.

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.

Reply to this message...
 
    
Johnny Lange (VIP)
Thanks for the help! I took back that book, because it didn't really explain
pointers and strings very well. Perhaps it's more for someone who experienced
with programing. So I picked up... How to program C++, fourth edition, by
Deitel. It's just native C++, (not MC++) I figured it might be better just to
learn "unmanged" C++ code first, then switch to MC++. I took one of the
figure examples in the book, edited it to make the program I was orignally
trying to make in MC++. The book explains everything much better, I actually
understand the stuff...lol

The following is working source code:
// Fig. 1.6:
// This program was edited to include some extras from the book
// "How to program C++ ,4th Edition" by Deitel

#include <iostream>

int main()
{
        int integer1;
        int integer2;
        int sum;
        int difference;
        int product;
        int quotient;
        int modulation;

        std::cout << "Enter first integer\n";
        std::cin >> integer1;

        std::cout << "Enter second integer\n";
        std::cin >> integer2;

        sum = integer1 + integer2;
        difference = integer1 - integer2;
        product = integer1 * integer2;
        quotient = integer1 / integer2;
        modulation = integer1 % integer2;

        std::cout << "Sum is\n " << sum << std::endl;
        std::cout << "difference is\n " << difference << std::endl;
        std::cout << "product is\n " << product << std::endl;
        std::cout << "quotient is\n " << quotient << std::endl;
        std::cout << "modulation is\n " << modulation << std::endl;
        return 0;
}

Reply to this message...
 
    
Peter van der Goes
"Johnny Lange" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
> Thanks for the help! I took back that book, because it didn't really
explain
> pointers and strings very well. Perhaps it's more for someone who
experienced
[Original message clipped]

great source of information and challenging exercises. Best of luck!

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.

Reply to this message...
 
    
Johnny Lange (VIP)
Thanks! :-)
[Original message clipped]

Reply to this message...
 
 




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification