8 Replies - 278 Views - Last Post: 11 February 2011 - 02:00 AM Rate Topic: -----

#1 YBang  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 24-January 11

code snippet

Posted 10 February 2011 - 10:50 PM

Hi


What does this code snippet do?

long sin=234567890;
while (sin > 0) {
cout << sin % 10 << endl;
sin /= sin;
}


Is This A Good Question/Topic? 0
  • +

Replies To: code snippet

#2 newclearner  Icon User is offline

  • D.I.C Regular

Reputation: 103
  • View blog
  • Posts: 302
  • Joined: 29-September 10

Re: code snippet

Posted 10 February 2011 - 11:30 PM

What does your logic say about it?
Was This Post Helpful? 0
  • +
  • -

#3 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 9039
  • View blog
  • Posts: 33,538
  • Joined: 27-December 08

Re: code snippet

Posted 10 February 2011 - 11:43 PM

Have you even run the code?
Was This Post Helpful? 0
  • +
  • -

#4 YBang  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 24-January 11

Re: code snippet

Posted 10 February 2011 - 11:51 PM

I'm kinda clueless hehe :surrender: :surrender:

I ran the code, its outputting 1 forever
Was This Post Helpful? 0
  • +
  • -

#5 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 9039
  • View blog
  • Posts: 33,538
  • Joined: 27-December 08

Re: code snippet

Posted 10 February 2011 - 11:54 PM

You probably want to divide sin by 10, not sin, to output each digit individually.
Was This Post Helpful? 2
  • +
  • -

#6 YBang  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 24-January 11

Re: code snippet

Posted 10 February 2011 - 11:57 PM

Thanks :bananaman:
Was This Post Helpful? 0
  • +
  • -

#7 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 9039
  • View blog
  • Posts: 33,538
  • Joined: 27-December 08

Re: code snippet

Posted 10 February 2011 - 11:57 PM

Glad I could help! :)
Was This Post Helpful? 0
  • +
  • -

#8 YBang  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 19
  • Joined: 24-January 11

Re: code snippet

Posted 11 February 2011 - 12:36 AM

Hey guys I'm really having trouble doing this assignment


#include <iostream>

using namespace std;

long sin;
char fsin[12];
char temp[12];
char outSin(sin){
    int i, k;
    sin = char fsin[12];
    for (i=0; i<12; i++) {
        k=11;
        temp [k] = fsin[i];
        if (k==4||k==7) {
                        temp [k] = "-";
                        k--;
                        }
        k--;
        }
        return temp;
        }
        
        
int main() {


cin >>sin;
while (sin > 0) {
cout<<sin % 10;
sin /= 10;
}
cout<<"Here is your SIN: ";
outSin();

cout<<endl;
system ("pause");
return 0;
}


        



This is my code (not so good)

and heres what I have to do:

Write a function that takes the SIN as a long (instead of a character array) as its first parameter. It must have a character array as a second parameter. The character array will hold the formatted sin number. You may count on the fact that the SIN will always have 9 digits (100000000 to 999999999).

Input: ######### 9 numbers
Output: ###-###-###

any feedback would be great
Currently working on the errors I'm getting

one of the says outSin cannot be used as a function

This post has been edited by YBang: 11 February 2011 - 12:40 AM

Was This Post Helpful? 0
  • +
  • -

#9 chinchang  Icon User is offline

  • Indie Game Developer
  • member icon

Reputation: 192
  • View blog
  • Posts: 725
  • Joined: 22-December 08

Re: code snippet

Posted 11 February 2011 - 02:00 AM

char outSin(sin){
// your code
}


You need to define a data type for the function parameter sin.

Also you are returning a char array not a character as your return type says. It should be char[]

Correct code:

char[] outSin(double sin){
// your code
}


I suggest you go over this tutorial by JackOfAllTrades.

This post has been edited by chinchang: 11 February 2011 - 02:01 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1