cant figure out whats wrong with my graphs

hello all;
this is the code that I'm getting.
http://i109.photobucket.com/albums/n...z13/graph1.jpg
this is what it should look like:
http://i109.photobucket.com/albums/n...nz13/graph.jpg
this is my code can someone plz take a look and tell me how to fix the graphs, so they can appear like the over link, and how to fix the warning that are appearing,thanks.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
using namespace std;

int main ()
{
ofstream outputFile;
outputFile.open("prog2_.txt"); //outputfile

int choice;

cout<<endl<<" Maths function plotter"; //Heading to program
cout<<endl<<"---------------------------------------";
cout<<endl<<"1. Plot function 1 3.5*sin(2*pi*t/8)\n"; //choice for plotting function 1
cout<<"2. Plot function 2 sqrt(t)\n"; //choice for plotting function 2
cout<<"3. Plot function 3 (At^2+Bt+C)/(t^2+1)\n"; //choice for plotting function 3
cout<<"4. Quit Program\n"<<endl; //choice for quiting program
cout<<"Make A Selection From The Menu: "; //user enters selection
cin>>choice;

{
if (choice==1) //Input selection made by user

{ const double pi = 3.141592654;

int i, j, x, y; //pi = 3.141592654;

//numbers of rows and columns in graph

const int row = 21;

const int col = 76;

char plot[row][col];


{
for (j = 20; j > -1; j--)
for (i = 1; i < col; i++)

plot[j][i] = '.';

}

cout << endl;

{
for (x = 0; x < 76; x++)
{
y = 3.5*sin(2.0*pi*x/8.0); //15*sin(2*pi*x/24)
plot[y][x] = '*';
cout << x << " " << y << endl;
}



}

{
for (j = 20; j > -1; j--)
{
for (i = 1; i < col; i++)

cout << plot[j][i];

cout << endl;
}

}


cout << endl;
return 0;
}
}

if(choice==4) //if user choice is 4
{
cout<<"Time to say good bye, THE END. "<<endl;
cout<< "Now writing information to the file.\n"; //writes information to the output file
outputFile<< " Student name : "<<endl;
outputFile<< " Student ID : " <<endl;

outputFile.close();
cout<<"Done.\n";
}



return EXIT_SUCCESS;
}

Last edited on
If you just put

if (choice==1)

and no { on the next line before another command is executed... The if will be only for the very next command line!

1
2
3
4
5
if (choice == 1) {
    // All your code for 1
} else if (choice == 2) {
    // All your code for 2
} else if ...


Opening { and closing } just sets a new subscope!!

Hope that helps ;-)
yeh it works, but how do i fix the warning and the graph, which should look like the second link above.
Last edited on
I tried the links and I get a "Page not found" :-/...

Could you repost it... Or just write out the warning ;-)
if u copy and past the above code into C++, u can see the warnings, they say:
warning C4244: '=' : conversion from 'double' to 'int', possible loss of data, and
warning C4101: 'sqrt' : unreferenced local variable.

and when u see the above, can u then see what is wrong with my graph, and how do i get the values for each line like in the second link:
this is how it looks like:
http://i109.photobucket.com/albums/n79/johnz13/graph1.jpg
this is how it is suppose to look like:
http://i109.photobucket.com/albums/n79/johnz13/graph.jpg

thanks
Last edited on
Topic archived. No new replies allowed.