The following code does everthing required except that because each numeral of the integer has to be entered individually the numbers appear in a vertical column. Question: is there a way of entering the numbers so that they appear on the screen in one row each having been entered individually? - int main ()
-
{
-
string s;
-
char c;
-
int sum=0,n=0,a[6]={0},num=0;
-
cout<<"Enter a 6 digit integer \n";
-
int i=0, fact=100000;
-
while(i<6)
-
{cin>>n;
-
a[i]=n;
-
num+=a[i]*fact;
-
fact/=10;
-
i++;
-
if(i>5) break;
-
}
-
cout<<"The integer entered is: "<<num;
-
-
if(num%3==0)cout<<" and is divisible by 3 (= "<<num/3<<" )";
-
else cout<<" and is not divisible by 3";
-
-
for(int i;i<6;i++)
-
sum+=a[i];
-
cout<<"\nSum of numerals is: "<<sum;
-
if(sum%3==0)cout<<" and is divisible by 3\n";
-
else cout<<" and is not divisible by 3\n";
-
cout<<"\n";
-
system("pause");
-
return 0;
-
}
7 4981
i`ve modified the code to include this nexrInt() funct as follows: - int nextInt()
-
{
-
int a[6]={0};
-
char ch;
-
int i=0;
-
while (cin.get(ch))
-
{
-
if (ch>= '0' && ch<='9')//next character is a digit
-
a[i]=ch;
-
i++;
-
if(i>=6) break;
-
}
-
for(int i=0;i<6;i++)
-
cout<<a[i]<<" ";
-
}
/*
Enter a 6 digit integer 123698
49 50 51 54 57 56 //this should be same as input but..........
*/
I'm obviously doing something wrong and illegal which is probably the while arguement.
It's the cin.get() echoing the enter key you used to enter the character.
Maybe you could try getchar().
That'll still have to same problem.
A possible solution might be a variant of gotoxy but that'll be a bit cumbersome and you'll have to take into account some constraints.
You will have to stop echoing the enter key. I don't remember if there is a way to do that.
oler1s 671
Recognized Expert Contributor
You would have to play around with the console functions ( assuming Windows) and change the way the console worked. And add in some additional code yourself. Have fun...
i`ve modified the code to include this nexrInt() funct as follows: - int nextInt()
-
{
-
int a[6]={0};
-
char ch;
-
int i=0;
-
while (cin.get(ch))
-
{
-
if (ch>= '0' && ch<='9')//next character is a digit
-
a[i]=ch;
-
i++;
-
if(i>=6) break;
-
}
-
for(int i=0;i<6;i++)
-
cout<<a[i]<<" ";
-
}
/*
Enter a 6 digit integer 123698
49 50 51 54 57 56 //this should be same as input but..........
*/
I'm obviously doing something wrong and illegal which is probably the while arguement.
I don't know about the echoing thing, but your cramming a char into an int, thats not gonna work the way you want it to.
Say somebody puts in 9 - Ascii '9' isn't the same as int( 9 ) so when you do a[i] = ch your not storing 9, your storing the character '9', which has int value of 57.
Or maybe I'm confused...
Thank you for your comments--wish i had your insights.
I couldn`t see the wood for the trees.
This is what i finally came up with which works fine. - int intManip(int n)
-
{ int m=0,sum=0;
-
int a[6]= {0};
-
for (int i=0;i<6;i++)
-
{ a[i]=n%10;
-
m=n/10;
-
n=m;
-
sum+=a[i];
-
}
-
return sum;
-
-
}
/*
Enter a 6 digit integer 369258
Sum of digits: 33
*/
Thank you all
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Mutley |
last post by:
I am finding an issue with the current DropDownList and ListBox ASP.NET Web
Controls.
I had a system set up for Arabic and a string that I put into a drop down
had a number. The letters were being displayed in Arabic but the numbers were
Latin. In other parts of my app ,Arabic numerals would appear as expected.
I found an MSDN link to the following web page that mentioned there was an
issue with the current DropDownList and ListBox ASP.NET...
|
by: Christopher Benson-Manica |
last post by:
Inspired by a thread on clc++, I decided to try it out...
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char *argv )
{
int i;
int result=0;
int this;
|
by: Patrick Blackman |
last post by:
How do you write regular numbers eg 1 23 475896 in roman numerals inC#
|
by: Kun |
last post by:
I have the following if statement that checks if a form is empty:
if form.has_key("date") and form.value != "":
date=form.value
else:
print "ERROR: No date entered!"
raise Exception
I would also like to add another if statement checking if 'date' has any
|
by: shanti.miller |
last post by:
I've got a grid that uses paging and displays a maximum of 10 records
at a time.
Sometimes the fields have a lot of data in them and the datagrid takes
up way too much horizontal space. I've tried setting the height and it
doesn't do anything. I can set the width to some very large number
like 3000px and that works ok, but it's a waste when the data doesn't
require that much space.
Is there a way to limit the height of the grid or of...
| |
by: jcris25 |
last post by:
pls help me on how to make a program by converting the day, month and year to a roman numerals...
im looking forward..tnx and god bless...
|
by: daming23 |
last post by:
Hi,
I'm taking an online C++ class and having some difficulty understanding the assignments. Can someone please look at the code I wrote to ensure validity? I am not asking for the answer just some guidance, I’m totally lost.
The assignment is as follow:
Write a prg to convert numbers entered in Roman Numeral to decimal. Your prg should consist of a class, say romanType. An object of the type romanType should do the following:
a. Store...
|
by: sweetamy |
last post by:
i am making an html form......it should check the values before accepting the data in the database,,,,,,,,,,,,,a field name USER NAME should check if the value entered is only a character value nd no numerals,,,nd if numerals r entered it should raie an exception i.e. alert msg...........how is it done using java script..........
thanx
|
by: kotlakirankumar |
last post by:
please help me out the program for converting the integers to roman
numerals using files in the c language from 1-5000 range send the
program to my
mail id ::::::: kotlakirankumar@gmail.com
thank you all
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |