Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Loops and addition/multipliacation help please

Hello,

I am trying to figure out this program on how to make it loop if Y is pressed and exit when N is pressed at the end of the program. The other problem I'm having is that this program can not have any decimals or negatives in it when the child enters the numbers. The last problem I'm having is that where the "Add _ together _ times and If I enter 2 2 it will give me 2+2+2+2=4 and the result will give me 2*2=4. The result part I have with out a problem...but its the expanding and taking down on the number of times the + signs shows up to give the answer to a child in simple form. The follow is the output for this program (below is the code I have so far):

(clear screen if Y is pressed to start over)
Welcome to the Multiplication Assistant

What is the 1st number? (example 2)<-- (I'm just showing what i'm getting right now for answers if I enter these numbers in)
what is the 2nd number? (example 2)<--

Add _(2) together _(2) times 2+2+2+2=4 <--(this is a problem...its not supppose to do that and I'm not sure how to fix or write it)
Result 2*2=4

Would you like to try again (Y/N)?

Can someone please help me out with this?

Thank you so much!!
ethompson

/*Multiplication Assistant*/
//Program Name: Program7.CPP

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

using namespace std;

int main()
{

double mult; // multiplier
double multand; //multiplicand
double result; //result
char response; //response

cout<<"Welcome to the Multiplication Assistant";
cout<<endl<<endl;

cout<<"What is the 1st number? ";
cin>>multand;

cout<<"What is the 2nd number? ";
cin>>mult;
cout<<endl;

result = multand * mult;

{if ((multand<=32767) && (mult<=32767));

cout<<"Add "<<multand<<" together "<<mult<<" times ";
cout<<multand<<" + "<<multand<<" + "<<multand<<" + "<<multand<<" = "<<result;
cout<<endl;

cout<<"Result ";
cout<<mult<<" * "<<multand<<" = "<<result;
cout<<endl<<endl;


response =='Y' || 'N';
cout<<"Would you like to try another (Y/N)? ";
cin>>response;
cout<<endl;

system("CLS");

else if ((multand>32767)&&(mult>23767));
cout<<"The number you entered is to high, please try again"<<endl;
}

cin.get();
cin.get();

return 0;
}
[3143 byte] By [ethompson] at [2007-11-11 8:51:24]
# 1 Re: Loops and addition/multipliacation help please
I share your problem with the loops, as for the 2+2+2+2=4, this is becuase you have it so it displays the multand 4 times. If your trying to show how many times it would appear I can't help you there. Also negatives and decimals do work. The reason you may not think negatives work is that 2 negatives multiplied by each other equals a positive number.
Typhus at 2007-11-11 21:01:00 >