Need help for my homework

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
closed account (Dy7SLyTq)
a) code tags
b) format your code
c) your missing semicolons
d) what error did you get?
Run-Time Check Felure #3- The variable "r" is being used without being initialized.This is the rror massege
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
cool ty alot
#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.