Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

C++ c++ stuck, Can give any suggestion or help?

views
     
TSbeng970804
post Oct 11 2016, 10:18 PM, updated 8y ago

Casual
***
Junior Member
323 posts

Joined: Apr 2015
From: Melaka


Any idea how can i solve this problem? Messing around at google but, still don't know the solution ..


Attached thumbnail(s)
Attached Image
Eventless
post Oct 11 2016, 10:22 PM

Look at all my stars!!
*******
Senior Member
2,641 posts

Joined: Jan 2003
Position in string determine the number of spaces behind the character?
slackinux
post Oct 11 2016, 10:32 PM

Casual
***
Junior Member
389 posts

Joined: Dec 2008
Each character's index position in the string equal to the space in front of each character 's print out.
TSbeng970804
post Oct 11 2016, 10:32 PM

Casual
***
Junior Member
323 posts

Joined: Apr 2015
From: Melaka


QUOTE(Eventless @ Oct 11 2016, 10:22 PM)
Position in string determine the number of spaces behind the character?
*
yah, means the space will add one by one going down each row
xboxrockers
post Oct 11 2016, 10:33 PM

On my way
****
Senior Member
661 posts

Joined: Dec 2011



QUOTE(beng970804 @ Oct 11 2016, 10:18 PM)
Any idea how can i solve this problem? Messing around at google but, still don't know the solution ..
*
yea I guess can play with for loop and increase number of spaces
TSbeng970804
post Oct 11 2016, 10:35 PM

Casual
***
Junior Member
323 posts

Joined: Apr 2015
From: Melaka


QUOTE(xboxrockers @ Oct 11 2016, 10:33 PM)
yea I guess can play with for loop and increase number of spaces
*
i trying for loop but kinda stuck..(ignore the error)


Attached thumbnail(s)
Attached Image
Eventless
post Oct 11 2016, 10:36 PM

Look at all my stars!!
*******
Senior Member
2,641 posts

Joined: Jan 2003
QUOTE(beng970804 @ Oct 11 2016, 10:32 PM)
yah, means the space will add one by one going down each row
*
So what is the problem that is stopping you from writing the code?
exBlasTer
post Oct 11 2016, 10:38 PM

Getting Started
**
Junior Member
77 posts

Joined: Jun 2011
Print space before you print the character
TSbeng970804
post Oct 11 2016, 10:42 PM

Casual
***
Junior Member
323 posts

Joined: Apr 2015
From: Melaka


QUOTE(Eventless @ Oct 11 2016, 10:36 PM)
So what is the problem that is stopping you from writing the code?
*
i still cant figure out the way to space infront of those character,,i only manage to print out character without spaces infront them.Below is what i done so far :


cout << "Enter text : ";
string txt;
getline(cin,txt);

int z = txt.length();

for (int i=0;i<=txt.length();i++)
{
cout << txt[i] << endl;
}
RookieDaddy
post Oct 11 2016, 10:44 PM

Getting Started
**
Junior Member
160 posts

Joined: Nov 2008


here...
CODE

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

int main(int argc, char** argv) {
   string s;
   
   cout << "Enter text ==> ";
   getline(cin, s);
   
   for (int i=0; i<s.length(); i++) {
       cout << setw(i+1) << s[i] << endl;
   }
   
return 0;
}

whistling.gif
TSbeng970804
post Oct 11 2016, 10:48 PM

Casual
***
Junior Member
323 posts

Joined: Apr 2015
From: Melaka


QUOTE(RookieDaddy @ Oct 11 2016, 10:44 PM)
here...
CODE

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

int main(int argc, char** argv) {
   string s;
   
   cout << "Enter text ==> ";
   getline(cin, s);
   
   for (int i=0; i<s.length(); i++) {
       cout << setw(i+1) << s[i] << endl;
   }
   
return 0;
}

whistling.gif
*
May i know this => (int argc, char** argv)
means what?
Eventless
post Oct 11 2016, 10:52 PM

Look at all my stars!!
*******
Senior Member
2,641 posts

Joined: Jan 2003
QUOTE(beng970804 @ Oct 11 2016, 10:42 PM)
i still cant figure out the way to space infront of those character,,i only manage to print out character without spaces infront them.Below is what i done so far :
cout << "Enter text : ";
    string txt;
    getline(cin,txt);

    int z = txt.length();

    for (int i=0;i<=txt.length();i++)
    {
        cout << txt[i] << endl;
    }
*
Create a new string with spaces and add the char end. Output the content of the new string.
http://www.cplusplus.com/reference/string/string/insert/
Eventless
post Oct 11 2016, 10:53 PM

Look at all my stars!!
*******
Senior Member
2,641 posts

Joined: Jan 2003
QUOTE(RookieDaddy @ Oct 11 2016, 10:44 PM)
here...
CODE

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

int main(int argc, char** argv) {
   string s;
   
   cout << "Enter text ==> ";
   getline(cin, s);
   
   for (int i=0; i<s.length(); i++) {
       cout << setw(i+1) << s[i] << endl;
   }
   
return 0;
}

whistling.gif
*
You shouldn't spoonfeed the answer here.
TSbeng970804
post Oct 11 2016, 10:59 PM

Casual
***
Junior Member
323 posts

Joined: Apr 2015
From: Melaka


QUOTE(Eventless @ Oct 11 2016, 10:52 PM)
Create a new string with spaces and add the char end. Output the content of the new string.
http://www.cplusplus.com/reference/string/string/insert/
*
Btw,is this forum have any topic to discuss c++ problem so i no need to post a new topic in future?
Eventless
post Oct 11 2016, 11:06 PM

Look at all my stars!!
*******
Senior Member
2,641 posts

Joined: Jan 2003
QUOTE(beng970804 @ Oct 11 2016, 10:59 PM)
Btw,is this forum have any topic to discuss c++ problem so i no need to post a new topic in future?
*
There isn't one. It is better to open a new thread with a specific questions in order to get answers that can help others with the same problem.
TSbeng970804
post Oct 11 2016, 11:07 PM

Casual
***
Junior Member
323 posts

Joined: Apr 2015
From: Melaka


QUOTE(Eventless @ Oct 11 2016, 11:06 PM)
There isn't one. It is better to open a new thread with a specific questions in order to get answers that can help others with the same problem.
*
Ok. Thanks for your guiding
xboxrockers
post Oct 12 2016, 10:24 AM

On my way
****
Senior Member
661 posts

Joined: Dec 2011



QUOTE(beng970804 @ Oct 11 2016, 10:35 PM)
i trying for loop but kinda stuck..(ignore the error)
*
C program Version. Btw I'm 17 know how to code and electronics Self Learned but ayam don't get good scholarships because they see result


CODE


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

void blank();
int main ()
{

char in[300];
int sLength = 0;
scanf("%s",in);
sLength=strlen(in);
int counter = 0;
int j = 0;
for (int i=0; i < sLength; i++)

 {
   printf("%c",in[i]);
   printf("\n");
   
   counter= counter + 1;
   for ( j =0; j < counter; j++)
   
    {
    blank();
   
    }  
 }


return 0;
}

void blank()
{
 printf(" ");
 
}




This post has been edited by xboxrockers: Oct 12 2016, 10:27 AM
xboxrockers
post Oct 12 2016, 10:30 AM

On my way
****
Senior Member
661 posts

Joined: Dec 2011



QUOTE(beng970804 @ Oct 11 2016, 10:48 PM)
May i know this => (int argc, char** argv)
means what?
*
argc is arguments counter means how many things you typed in terminal Exp: how are you is counted as 3 arguments

argv is argument vector Exp you can access why you type in terminal, Exp : argv[0] will give you how argv[1] will give you are argv[2] will give you

blush.gif
e_mc_square
post Oct 12 2016, 10:34 AM

Enthusiast
*****
Senior Member
751 posts

Joined: Dec 2008


QUOTE(beng970804 @ Oct 11 2016, 10:48 PM)
May i know this => (int argc, char** argv)
means what?
*
You can ignore that line.
I believe you using Visual C++. Some newer compiler will have that line of code in Main()
Just ignore the line if you are still new. You can even delete it.
dstl1128
post Oct 12 2016, 11:04 AM

Look at all my stars!!
*******
Senior Member
4,463 posts

Joined: Jan 2003
C shouldn't be that long. And scanf() choke on spaces.
CODE

#include <stdio.h>
int main()
{
   int c, count=0;
   while ((c = getchar()) != '\n')
       printf("%*c\n", ++count, c);
   return 0;
}


2 Pages  1 2 >Top
 

Change to:
| Lo-Fi Version
0.0165sec    0.44    6 queries    GZIP Disabled
Time is now: 29th March 2024 - 10:03 PM