I'm supposed to write a code in do-while statement...I've done the majority of it, but I know there's errors with it....how do I fix it? Code: #include <iostream> using namespace std; int main() { //declare variables int multiplicand = 0; int product = 0; int multiplier = 0; //input values cout << "Multiplicand (negaqtive number to end): "; cin >> multiplicand; //calculations do { (multiplicand >= 0); (multiplier = 1) (multiplier < 10); (multiplier += 1); { while product=multiplicand * multiplier; cout << multiplicand << "*" << multiplier << "=" << product << endl; } //display cout << endl; cout << "Multiplicand (negative number to end): "; cin >> multiplicand; return 0;
Okay, I fixed it a little bit and it is supposed to be a C++ code but it's still not running properly and I'm not entirely sure where the error is. I need to make sure the code has post test loops in it and the particular problem is to allow one or more multiplication tables and the multiplier allows 1-9. What do I need to do? Code: //Directives #include <iostream> using namespace std; int main() { //declare variables int multiplicand = 0; int product = 0; int multiplier = 0; //input values cout << "Multiplicand (negaqtive number to end): "; cin >> multiplicand; //calculations do { multiplicand * 1; cout << multiplicand << endl; } while (multiplier < 10); //display cout << endl; cout << "Multiplicand (negative number to end): "; cin >> multiplicand; return 0;
Crap. I got the thing to run, but when I enter the multiplicand....all it does is repeat the number. Constantly. Oops. I guess I messed up somewhere. Any ideas, please?
What does this line do? Code: multiplicand * 1; OK, more accurately: I know what it does, but what do you think it will do?
Hello I am a student at UAT I think I see your problem at lteast part of it. If it repeats the number entered continually it sounds like a looping error. so lets look at loops. Code: do { multiplicand * 1; cout << multiplicand << endl; } while (multiplier < 10); Now a do / while loop will do something repeatedly until the conditions in the while branch are met. so if it constantly repeats a number over and over in the cout, then the problem must be here somewhere. My advice to stop the first problem of repeating numbers is fix the loop. As for the logic error ( that would be the calculations going wrong) you should start with some psuedo code. For instance, what are you trying to do. are you trying to multiply the numbers up until the "multiplicand" using the multiplier? If so then your logic should read like this: multiply my multiplicand by my multiplier out put my result add one to my multiplier check if my multiplier is equal to my multiplicand while it is not repeat the process. It will help if you get into a habit of writing this down, then use these comments as commentary for the code. That will help those of us helping you understand your problem better and it will better define what you are trying to accomplish.