Jump to content

[Help] I got problems

- - - - -

  • Please log in to reply
3 replies to this topic

#1
Pagn

Pagn

    Newbie

  • Members
  • Pip
  • 3 posts
Hey! I wanted to make a calcultor for multiplation only. When i compiled, it had 1 succeeded. But it have a little bug at the end. Could you please fix it. Thanks!

#include <iostream>

using namespace std;


int main()

{

	int a;

	int b;

	int d;


	cout << "Write a number: ";

	cin >> a;


	cout << "Write another number: ";

	cin >> b;


	if(d != 0)

	{

		d = a * b;

		cout << a << " x " << b << " = "; cin.get();

	}


	cin.get();

    return 0;

}


#2
simislovas

simislovas

    Newbie

  • Members
  • Pip
  • 9 posts
does this do what you want?


#include <iostream>

using namespace std;


int main()

{

	int a;

	int b;

	int d;


	cout << "Write a number: ";

	cin >> a;


	cout << "Write another number: ";

	cin >> b;


	d = a * b;

	cout << a << " x " << b << " = "<<d;

	cin.get();

	

	cin.get();

    return 0;

}



#3
Sdyess

Sdyess

    Newbie

  • Members
  • Pip
  • 2 posts
What? Why are you using the cin.get() method?

I'm guessing it isn't printing out your end result? Another problem is that d isn't initialized, so when that if statement checks, it should error. It only requires the use of 2 variables, because they can just be multiplied together in the last statement.


Try using this instead.


#include <iostream>


using namespace std;


int main()

{

	int a, b;

	cout << "Write a number: ";

	cin >> a;

	cout << "Write another number: ";

	cin >> b;

	cout << a << " X " << b << " = " << a * b << endl;

}



#4
simislovas

simislovas

    Newbie

  • Members
  • Pip
  • 9 posts
Sdyess i wanted to fix the same, but thought i'll only fix what was wrong :)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users