Bad array Declarator

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • IndoSun
    New Member
    • Aug 2018
    • 1

    #1

    Bad array Declarator

    I have to create an array of 10 strings and put 10 quotes in each. I also have to create a while loop which I don't know where to start. I am having trouble compiling and I can't find any of this online.. Its driving me crazy - I am new to programming.

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.IO;
    #include "stdafx.h"
    #include <string>
    string Quote;
    using namespace std;
    
    
    
    int main()
    {
        // String Array
        string Quote[9];
        // Attach Values
        Quote[0] = "Don't cry because it's over, smile because it happened.";
        Quote[1] = "Be yourself; everyone else is already taken.";
        Quote[2] = "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.";
        Quote[3] = "A room without books is like a body without a soul.";
        Quote[4] = "You know you're in love when you can't fall asleep because reality is finally better than your dreams.";
        Quote[5] = "You only live once, but if you do it right, once is enough.";
        Quote[6] = "If you tell the truth, you don't have to remember anything.";
        Quote[7] = "A friend is someone who knows all about you and still loves you.";
        Quote[8] = "To live is the rarest thing in the world. Most people exist, that is all.";
        Quote[9] = "Without music, life would be a mistake.";
        return 0
    }
    It says bad array decorator when it says string Quote[9]
    Last edited by zmbd; Aug 12 '18, 09:44 PM. Reason: [z{merged related posts}{Please use the [CODE/] format in the toolbar for script/SQL/etc}]
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    It has been awhile since I've used C
    I am most likely wrong; however, I am not sure that line 9 is needed...

    I also think you need (most likely the error):
    string Quote[10];

    and I always used the typedef
    typedef char * string;

    Sorry I don't have a C compiler installed so I can't double check - WeaknessForCats will be along soon and will know the answer

    Thank you for showing your work - normally we will not answer homework type problems unless the poster has shown that they've made an effort to solve the problem on their own first :-)
    !Two Thumbs Up!
    Last edited by zmbd; Aug 12 '18, 10:01 PM.

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      You created an array of 9.

      That would be elements 0,1,2,3,4,5,6,7 ,8.

      Comment

      • dev7060
        Recognized Expert Contributor
        • Mar 2017
        • 656

        #4
        As per the requiments, you can use a 2D character array. Quote[x][y] , here x is 10 but y needs to be mentioned (size of the maximum length quote).

        Implementation for outputting:

        Code:
        for (i=0; i<x; i++){
           printf("%s", Quote[i]);
        }

        Comment

        Working...