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

Pages: 1-

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 13:30

i forgot the delete cmath which is not necessary

Name: Anonymous 2011-12-20 13:33

yes

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
}

Name: >>4 2011-12-20 14:08

>>4
forgot to mention Sepples is shit

Name: Anonymous 2011-12-20 15:13

>>4
omg unoptimized

Name: Anonymous 2011-12-20 15:18

>>6
fuck that, it prints the letter i instead of the number i, derp
where's FV to Coptmize this shiet with some l33t preproccessor magic?

Name: Anonymous 2011-12-20 16:39

C++
stopped reading right there

Name: Anonymous 2011-12-20 19:12

-[,---------------------------------
--------------------->+<]>>>+++++++[
<++++++++++++>-]<.>++++[<+++++>-]<.-
--.>+++++++[<---------->-]<+.>+++[<+
++++++>-]<+.>+++[<------->-]<-.>++++
++++[<+++++++++>-]<+.++++++++++.>+++
++++[<------------>-]<+.>++++++++[<+
+++++++>-]<+.>+++[<++++++>-]<+.>++++
+++[<------------>-]<.[-]>[-]<>+++++
+++++[<++++++++++>-]<.+++++.--.++.++
+++++++++.>+++++++[<------------>-]<
.<++++++++++++++++++++++++++++++++++
++++++++++++++.>++++++++++++++.

Name: Anonymous 2011-12-20 19:25


#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int main() {
    char figure, buf[128], *loc;
    printf("\nWhat character do you want to search for? ");
    scanf("%c", &figure);
    printf("Enter the searchable string (no spaces): ", figure);
    for (;;) {
        scanf("%127s", buf);
        loc = strchr(buf, figure);
        if (loc) {
            printf("The digit was at index %u\n", (unsigned int) (loc - buf));
            return 0;
        }
        if (strlen(buf) < 127)
            break;
    }
    printf("\nThe character was not located\n");
    return 1;
}

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