1 Replies - 230 Views - Last Post: 30 November 2017 - 06:17 PM Rate Topic: -----

#1 VileB   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 30-November 17

How to exclude non integers with an if statement

Posted 30 November 2017 - 05:40 PM

I want to make it so the user can only input integers. I figured the best way to accomplish this was using an if statement but I don't know what goes in i. I've looked around in the website and found questions extremely similar to mine but their code is written in a format I don't understand (uses cin cout) can anyone give me a hand?

int main()
{
	int a,b,r;
	printf("input your first number: \n");
	scanf_s("%d",&a);
	printf("input your second number: \n");
	scanf_s("%d",&B)/>/>;
	if ( )

	r=a+b;
	printf("your number is: %d",r);
	_getch();
	return 0;


This post has been edited by Skydiver: 30 November 2017 - 06:37 PM
Reason for edit:: Fixed botched code tags. Thanks for trying.


Is This A Good Question/Topic? 0
  • +

Replies To: How to exclude non integers with an if statement

#2 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3796
  • View blog
  • Posts: 13,742
  • Joined: 08-August 08

Re: How to exclude non integers with an if statement

Posted 30 November 2017 - 06:17 PM

What do you think this will output?
#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
	int number;
	number = 112.9;

	cout << number << endl;

	return 0;
}


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1