Thread: help a beginner

  1. #1
    Registered User
    Join Date
    Jan 2016
    Posts
    2

    Exclamation help a beginner

    hello
    I know that question is very simple for all of you but it's not for me
    i just need the answers
    thank you all

    1- write a program that reads 2 strings of the same length from the user and prints"same" if these strings are identical
    else it prints"different"

    2- find and correct the error

    Code:
     void fun(const int b[],int n)
    { for(int i=0,i<n,i++)cout<<++b[];}
    void main( ){ int a[5]={2,4,3,5,6}:fun{a,5);}


    Code:
     int b[9]={0,1,2,3,4,5,6,7,8,9};
    for (int i=0,i<=9.i++)b[i]=i;


    3-what will the output of the following code
    Code:
    float x[10]={5.5,6.5,7.5,8.5,9.5,12.5,14.5,16.5,18.5,20.5}
    cout <<static cast<int>(x[9/2]/2;


    4- write a program that reads the mode value of the following data elements
    Code:
    {1,1,2,2,3,5,5,9,8,7,7,5,2,75,2,2,4,4,)

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by tomtoma
    I know that question is very simple for all of you but it's not for me
    i just need the answers
    You are right to say that these questions are very simple for me. However, were I to take that little bit of time of mine to write out the answers for you to use verbatim, they will always be very hard for you, i.e., you will remain a beginner. Forever. That's all very well if you were hiring me to code for you, but these are obviously homework questions, so nope: you're trying to cheat.

    As such, no, you need to answer the questions yourself. We might be able to help you along, but you need to take effort to understand and make your best attempts.

    For starters, you need to indent the code properly, e.g.,
    Code:
    void fun(const int b[],int n)
    {
        for (int i = 0, i < n, i++)
            cout << ++b[];
    }
    
    void main()
    {
        int a[5] = {2, 4, 3, 5, 6}:
        fun{a, 5);
    }
    This will allow you to read the code more easily, and hence allow you to find the errors in the code more easily.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jan 2016
    Posts
    2
    I swear I'm not trying to cheat, It's old exam i want to find it's answers ,i can even upload the exam paper to prove that it an old exam,but I think it doesn't important because even i did it no one will give me the answers

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Take question #2: what mistakes did you spot? List all of them. Then, now that you are no longer in the exam hall, compile the program. What errors are reported by your compiler? Fix the errors that you spotted earlier and compile again. What errors are still reported by your compiler?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User Arhaikos's Avatar
    Join Date
    Jan 2016
    Location
    Greece
    Posts
    14
    Just a little boost:

    Code:
    #include <iostream>
    
    using namespace std;
    
    void fun(const int b[], int n)
    {
        for (int i = 0; i < n; i++)
        {
            cout << b[i];
        }
            
    }
    
    int main()
    {
        int a[5] = { 2, 4, 3, 5, 6 };
        fun( a, 5);
        
    }
    Last edited by Arhaikos; 01-30-2016 at 08:49 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Question -- From Absolute Beginner's Guide to C
    By Dghelerter in forum C Programming
    Replies: 5
    Last Post: 12-26-2013, 01:30 PM
  2. Please Help!! I'm A Beginner...
    By jimgeor in forum C Programming
    Replies: 3
    Last Post: 05-28-2012, 04:04 AM
  3. I'm a beginner. HELP!
    By jimgeor in forum C Programming
    Replies: 10
    Last Post: 04-03-2012, 10:36 PM
  4. Beginner =(
    By Kandy in forum C Programming
    Replies: 1
    Last Post: 11-08-2005, 02:18 PM
  5. Windows programming for beginner (Absolute beginner)
    By WDT in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2004, 11:21 AM

Tags for this Thread