Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C++ problem

  1. Jul 6, 2007 #1
    i wish to ask about the c++:
    when we should use this and why we should use this?
    why we cant direct use cin>>?
  2. jcsd
  3. Jul 6, 2007 #2
    The >> operator only reads one token at a time so it will read one word (or number or other element for which it is defined) and return. The getline function reads a complete line. So use >> to read single words, use getline to read input lines that may contain spaces.
  4. Jul 9, 2007 #3
    can anybody help me how to get this output?
  5. Jul 9, 2007 #4

    Math Is Hard

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    You need to give us more information about what you are trying to do here. Are there specific integers, float numbers, and characters that you want to print where you have the question marks? Or do you simply want to "cout <<" those three lines with question marks at the end? Or are you trying to prompt the user of your program to enter something?
  6. Jul 9, 2007 #5
    the question:
    write prgramme that will ask user to enter 5 integer numbers, 4 float numbers and 3 characters. then store them in arrays.
    5 integers numbers are?
    4 float numbers are?
    3 characters are?
  7. Jul 9, 2007 #6
    So what have you done so far with the question?
  8. Jul 9, 2007 #7
    i was a programme but some error occur.
  9. Jul 9, 2007 #8
    Well post your program here, and we'll try to help. You can't expect us to give you a ready made program.
  10. Jul 9, 2007 #9
    i get it already!
    thanks for everybody.

    #include <iostream>
    #include <cstring>
    using namespace std;
    int main()

    int a[5], i;
    float b[4];
    char c[3];

    cout<<"plz enter a integer"<<endl;

    for (i=0; i<8; i++){

    cout<<"\n 5 integer are: ";
    for (i=0; i<5; i++){
    cout<<a<<" ";


    cout<<"plz enter a float"<<endl;

    for (i=0; i<4; i++){

    cout<<"\n 4 float are: ";
    for (i=0; i<4; i++){
    cout<<b<<" ";


    cout<<"plz enter a character"<<endl;

    for (i=0; i<3; i++){

    cout<<"\n 3 integer are: ";
    for (i=0; i<3; i++){
    cout<<c<<" ";


    return 0;
  11. Jul 9, 2007 #10
    now i dont know how to answer this question:
    write a programme that prompt the user to enter a string and output the string in uppercase letters.(use a character array to store the string)
    can anybody help me?
  12. Jul 9, 2007 #11
    Although there are built in functions to do this in ctype.h, I think you should try using the ASCII equivalent values of each letter of the string, so as to change it to corresponding uppercase value. Do you know how to do this?
  13. Jul 9, 2007 #12


    User Avatar

    In C++ with std::string and that.
    Code (Text):
    std::transform(str.begin(), str.end(), str.begin(), std::toupper);
    Similar with C character strings, except you'd have to manually loop through each character yourself and call toupper().
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: C++ problem
  1. C problem (Replies: 3)

  2. C++ problem (Replies: 4)

  3. A C problem (Replies: 3)

  4. Problems in C++ (Replies: 5)

  5. A problem with C (Replies: 4)