Hi everyone,

I'm kinda new to this - both to DaniWeb and to C++ programming, so I hope you'll bear with me and my rookie questions.

Anyways, I'm trying to build a little C++ program that my daughter can use to practice multiplication. It's supposed to receive two numbers and multiply them, and then ask whether the user wants to go again. Probably sounds simple to most of the people around here, but all I get is a totally blank console window! What am I doing wrong?

I would be grateful for any pointers in the right direction.

Here is my code:

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

int main()
{
	dos_console(850);
	bool start = 1;

	while (start == 1)
	cout << "\n";
	cout << "Practice multiplication\n";
	cout << "=======================\n";
	cout << endl;

	double tal1;
	double tal2;
	
	cout << "Enter factor 1: ";
	cin >> tal1;

	cout << "Enter factor 2: ";
	cin >> tal2;

	cout << "\n";
	cout << "Answer: " << tal1 << " * " << tal2 << " = " << tal1 * tal2 << "." << endl;
	cout << "\n";
	cout << "Again? (j/n)" << endl;

	char ch;                                              // Declare variable "ch"
    do
    {
      ch = _getch();                                      // Receives a character to char "ch"    
      if (ch == 'j')                                     
	  { 
	    start = 1;                                        // Condition for main loop becomes "true"
        system("cls");                                    // Clears screen
	  }                                    
      if (ch == 'n')                                     
        start = 0;                                        // Condition for main loop becomes "false"
    }
	while (ch != 'j' && ch != 'n');                       // Runs if neither 'j' or 'n' is pressed

	return 0;
  }                                                       // End of main loop

Recommended Answers

All 2 Replies

while (start == 1)
  cout << "\n";

Those two lines will be executed forever, you need to indicate all the code that belongs inside the while loop by putting it in { }'s

Of course! That did the trick!
Thank you!

while (start == 1)
  cout << "\n";

Those two lines will be executed forever, you need to indicate all the code that belongs inside the while loop by putting it in { }'s

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.