Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have to make a simple coding project on c++. i need to move "*" character in y=mx+c. i wrote a cup of coding lines to generate straight lines. now i have to move this in that path. plz help me.....

What I have tried:

#include <iostream>
#include <math.h>
#include<Windows.h>
using namespace std;

int pth (int x)  {
    return -1*x+1;
}

int main()  {
    int i,j,y;
    for (int x=-10;x <= 10;x++)  {
        for ( i=-10;i <= x;i++)  {
            if (i==x) {
                y=pth(x);
               // cout<<"x=";
                //cout<<x;
                //cout<<"y=";
                //cout<<y;

                for(j=-10;j<=y;j++) {
                   if(j==y)
                        cout << "*";
                    else
                        cout << " ";
                }
            }
        }
        cout << "\n";
system("cls");
Sleep(20);
    }
    cin.get();
    return 0;
 }
Posted
Updated 6-Oct-18 2:04am

Simple: Change your pth function to use the new formula instead of -1*x+1 - which is a special case of y = mx + c where m == -1, and c == 1
 
Share this answer
 
v2
Probably you need to use the Windows Console API[^].
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900