Need help for my homework

Oct 24, 2013 at 4:13pm
Hi all i got problem with my c++ code can some one tell me where is my misstake coz i really need this homework.....


#include <iostream>
using namespace std;
int main()
{
unsigned int r,c;
cout<<"rows:" ; cin>>c;
cout<<"colimns:" ; cin>>c;
if(r<c)
cout<<"A: ("<<r<<";"<<r<<")"<<endl
<<"B:"<<r<<endl
<<"V:"<<(r-1)*r/2+r*(c-r)<<endl;
else
cout<<"A:("<<c<<","<<c<<")"<<endl
<<"B:"<<c<<endl
<<"V:"<<(c-1)*c/2<<endl;
return 0;
}
Last edited on Oct 24, 2013 at 4:13pm
Oct 24, 2013 at 4:16pm
closed account (Dy7SLyTq)
a) code tags
b) format your code
c) your missing semicolons
d) what error did you get?
Oct 24, 2013 at 4:22pm
Run-Time Check Felure #3- The variable "r" is being used without being initialized.This is the rror massege
Oct 24, 2013 at 4:52pm
You need to give r a value to manipulate it, even if it is just 0. I assume you accidentally put cin>>c; beside rows instead of cin>>r;. You are also missing braces for your else statement.


//begin

#include <iostream>
using namespace std;
int main()
{
unsigned int r,c;
cout<<"rows:" ; cin>>r; //this was cin>>c before
cout<<"colimns:" ; cin>>c;
if(r<c)
cout<<"A: ("<<r<<";"<<r<<")"<<endl
<<"B:"<<r<<endl
<<"V:"<<(r-1)*r/2+r*(c-r)<<endl;
else
{
cout<<"A:("<<c<<","<<c<<")"<<endl
<<"B:"<<c<<endl
<<"V:"<<(c-1)*c/2<<endl;
}
return 0;
}

//end

P.S This is some of the messiest code i have ever seen
Oct 24, 2013 at 5:16pm
cool ty alot
Oct 26, 2013 at 7:19am
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
unsigned int r,c;
cout<<"rows:" ; cin>>c;
cout<<"colimns:" ; cin>>c;
if(r<c)
cout<<"A: ("<<r<<";"<<r<<")"<<endl
<<"B:"<<r<<endl
<<"V:"<<(r-1)*r/2+r*(c-r)<<endl;
else
cout<<"A:("<<c<<","<<c<<")"<<endl
<<"B:"<<c<<endl
<<"V:"<<(c-1)*c/2<<endl;
getch();
}
Topic archived. No new replies allowed.