willywonka 0 Newbie Poster

I have to write a program for my assignment that does a quote.
It has to have a void function that validates a string and and integer entered. Other wise I would have solved the problem with a simple menu and integers.

The entries has to be one of five cake choices and the amount needed.
In this case, chocolate, carrot, coffee, fruit, custard.
It has to keep prompting the user until one of these options are entered.

It has to have a do{....}while loop.

I tried a switch statement as an option in the loop but it tells me the about parameters being to long.
Was I on the right track?

Can you accumulate information in a void function to be used in the main function without using global variables???

Please just help me with an idea of how to compound all this string options and to use them as a condition in the do...while loop. Even a totally unrelated example will be appreciated. I will appreciate ANY pointer in the right direction.

willywonka 0 Newbie Poster

the answer is in the hint. I'll add that you need to use the hint for five loops, and for the last line use a separate set of three loops. The answer is right there. look at it again. It is not as hard as you think, I promise.
Each character in the line should have its own loop.

willywonka 0 Newbie Poster

Thanks for all the help guys. I got it in the end. Here is my program, tell me if this is similar as to what you would have done;

// Draws shape V
#include<iostream>
using namespace std;

void drawShape (int nrP)
{
    for (int i=1; i <= nrP-1; i++)
    {   
        int x,y;
        x=i-1;
        y=2*nrP-2*i-1;

        for (int j=1; j<=x; j++)
         cout << "^";
        for (int j=1; j<=1; j++)
         cout << "#";
        for (int j=1; j<=y; j++)
         cout << "^";
        for (int j=1; j<=1; j++)
         cout << "#"; 
        for (int j=1; j<=x; j++)
         cout << "^";         

         cout << endl;
    }
    // Last row
        for (int j=1; j<=nrP-1; j++)
         cout << "^";
        for (int j=1; j<=1; j++)
         cout << "#";
        for (int j=1; j<=nrP-1; j++)
         cout << "^";
    cout << endl;
} 


int main ()
{
    int nr;

    cout << "Number of rows : ";
    cin >> nr;
    cout << endl;
    drawShape(nr);
    cout << endl;

    return 0;
}
willywonka 0 Newbie Poster
int nrP = 6;
for ( i = 1 ; i < nrP ; i++ ) {
  cout << i << " " << (2 * nrP - 2 * i - 1) << endl;
}

Notice anything about the sequence of numbers?

I have also tried the following, but it goes into an infinite loop, but I can't see why. I think i am over thinking this problem or I am trying to overcomplicate it. Here's what I tried:

void drawShape (int nrP)
{
    for (int i=1; i <= nrP; i++)
    {    
        for (int j=i-1; j<=i; j++)
         cout << "^";
        for (int k=1; k <=i; k++)
         cout << "#";
        for (int l=(2*nrP-2*i-1); l<=i; l++)
         cout << "^";
         
    cout << endl;
    }
    cout << endl;
}
willywonka 0 Newbie Poster

First, have you started any code? What parameters are you going to use in your code? Is it a simple iostream or an fstream that's required. Post what you have so far so we can help you out.

I have started with the problem. This is what i have so far :

// Draws shape V
#include<iostream>
using namespace std;

void drawShape (int nrP)
{
    for (int i = 1; i <= nrP; i++)
    {    for (int j=2; j<=i; j++)
         {cout << "#";
            for(int j=0; j < i; j++)
            cout << "^";  }
          
}

int main ()
{
    int nr;
    
    cout << "Number of rows : ";
    cin >> nr;
    drawShape(nr);
    
    return 0;
}

I just can't figure out where to put the formula provided as a hint, and the loops inside the function have me baffled. I feel a little lost, especially with the last row. how do get just one '#' sign in the last row. does it require a different loop all of its own??? Does the formula make provision for it. I am busy catching up on my calculus also, thus you can see i bit quite a big bit off for myself.

willywonka 0 Newbie Poster

Hi all, I am a first year student at the university of South Africa. I am doing my degree via correspondence, thus no lectures. I am working through the prescribed book as best i can but they still assume a little bit of fore knowledge of programming which i don't have! Please tolerate me for asking what should probably be a very easy question for you all.

They want me to write a void function which does the following. A number is entered, eg 6 ant then the following should be the output;

#^^^^^^^^^#
^#^^^^^^^#^
^^#^^^^^#^^
^^^#^^^#^^^
^^^^#^#^^^^
^^^^^#^^^^^

I know that a 'for' loop is required to do this, but I cant figure out how many to nestle!?

The formula (2 * nrP - 2 * i - 1) is given as a hint where 'nrP' is the number of rows entered by the user for the function to use and 'i'
will be the row generated by the loop. I have no examples of this in my text book to refer to for help.

If someone could just steer me in the right direction it will already be a huge help.

PLEASE HELP!!

thanks