Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Program help

Name: Anonymous 2011-12-20 13:26

i want to write a program in C++ that shows which digit has the figure we want in a given number.

for example: user enters 456813 and wants to know where 6 is. program prints "6 is in the third digit." or something like that it doesn't matter. my not-good-looking was:

#include<iostream>
#include<cmath>
using namespace std;

int main()
{
int x;

cout << "enter 5 digit number : " ;
cin >> x;
int a;
cout<<"enter the figure you want to search: ";
cin>>a;
int y = x;

for(int i = 1;i < 6;i++)
{
for (int j = 1; j < 6;j++)
{


x= x / 10;

if(x % 10 == a)
cout <<"(from end) " << j+1 << " . digit has" <<a<< endl;
}
}
if(y % 10 == a)
cout <<"(from end).digit has" <<a<< endl;

return 0;
}

Name: Anonymous 2011-12-20 14:05

the fuck you trying to do?

readinto string, check entire string for the '6' char
for(int i=0;str_length;++i)
{
if(str[i]=='6') cout << "6 at i" << endl
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List