The Best Cyprus Community

Skip to content


C++ Problem

Feel free to talk about anything that you want.

C++ Problem

Postby Acunga » Tue Jun 12, 2007 1:07 pm

Where is my mistake:
#include <string>
#include <iostream>
using namespace std;


int main()
{
int k,a =0,i=0,b=0,j=0,h=0;
char q;

again:for(j=0;j<1;j++)
{cout << "\nEnter a value: ";
cin >> a;
for (h=0;a!=b;h++)
{cout << "Guess the value: ";
cin >> b;
}
cout << "Right value!, you have " << h << " tries.";}
if(j==0)
k=h;}
cout << "Dou you want to end the game:Y/N? ";
cin >> q;
if (q == 'N' || q == 'n')
goto again;
else
system("pause");
return 0;}

The compiler is talking about some destrukctors, constructors needed after << in the last cout.But in general it gives 100 mistakes.So i removed the bracket near it and it has compiled, but the point is that It is necessary the thing to repeat 2 times before ask to end
Acunga
Member
Member
 
Posts: 71
Joined: Fri May 25, 2007 12:18 pm

Postby dms007 » Tue Jun 12, 2007 2:05 pm

there he goes again with another one of his homeworks.

Where is my mistake:

taking a computer major.
dms007
Regular Contributor
Regular Contributor
 
Posts: 1350
Joined: Tue Jul 12, 2005 9:21 am
Location: limassol

Postby rick-kendall » Tue Jun 12, 2007 3:31 pm

3 open curly braces and 4 to close and why have you escaped the " , thought you only need to escape " when displayed as text inside other quotes
rick-kendall
Member
Member
 
Posts: 90
Joined: Wed Jan 18, 2006 9:43 pm
Location: Pissouri

Re: C++ Problem

Postby cyprusgrump » Tue Jun 12, 2007 5:23 pm

Acunga wrote:Where is my mistake:

Not writing it in BASIC
User avatar
cyprusgrump
Main Contributor
Main Contributor
 
Posts: 8520
Joined: Thu Sep 01, 2005 4:35 pm
Location: Pissouri, Cyprus

Postby bigOz » Tue Jun 12, 2007 5:31 pm

May I suggest you try and use indentations and curly brackets on separate lines. When I first started C++ this was one of th eimportant things we were taught! As you can see from below, it becomes very easy to see you have one extra curly bracket in the area printed red! Get rid of it...
I do not know what the code is exactly doing but confirm if the two statements after k=h in the red area are supposed to execute under the if condition or not. If they are you need to add opening and closing curly brackets for th ethree statements that follow.

Also what exactly is the purpose of the "for(j=0;j<1;j++) " loop when all its doing is running it it only once? If that's the loop that is supposed to run th eprocess twicw try replacing "j<1" with "j=1" or "j<2"

#include <string>
#include <iostream>
using namespace std;


int main()
{
int k,a =0,i=0,b=0,j=0,h=0;
char q;

again:for(j=0;j<1;j++)
{
cout << "\nEnter a value: ";
cin >> a;
for (h=0;a!=b;h++)
{
cout << "Guess the value: ";
cin >> b;
}
cout << "Right value!, you have " << h << " tries.";
}
if(j==0)
k=h;
}
cout << "Dou you want to end the game:Y/N? ";
cin >> q;

if (q == 'N' || q == 'n')
goto again;
else
system("pause");

return 0;
}
User avatar
bigOz
Regular Contributor
Regular Contributor
 
Posts: 1225
Joined: Fri May 11, 2007 11:19 am
Location: Girne - Cyprus

Postby Peterc » Tue Jun 12, 2007 5:40 pm

:shock:
User avatar
Peterc
Contributor
Contributor
 
Posts: 516
Joined: Tue May 23, 2006 4:02 pm
Location: Cyprus

Postby Crivens » Tue Jun 12, 2007 6:19 pm

Ah, all my Cyprus questions have now been answered. Now I'm off to my programming forums to ask a few questions about duty free tax on cars being imported to Cyprus and where to find the best deal in Limassol for one of those metal car cover things I see around in apartment car parks.... :D

Cheers

Ps. And yes, do your own homework. I mean grief, when I did my CS degree the web (actually wasn't called that I believe) wasn't that useful so we had to rely on good old copying of each others work :) But these days, c'mon! (HINT : Google is your friend, unless you want someone to literally plop the answer into your lap. Might as well ask someone to write an app for you...)
Crivens
Contributor
Contributor
 
Posts: 420
Joined: Fri Apr 08, 2005 7:55 pm
Location: Limassol

Postby Acunga » Tue Jun 12, 2007 8:44 pm

bigOz wrote:May I suggest you try and use indentations and curly brackets on separate lines. When I first started C++ this was one of th eimportant things we were taught! As you can see from below, it becomes very easy to see you have one extra curly bracket in the area printed red! Get rid of it...
I do not know what the code is exactly doing but confirm if the two statements after k=h in the red area are supposed to execute under the if condition or not. If they are you need to add opening and closing curly brackets for th ethree statements that follow.



Yes, I was thinking the same.Well here in my university i have missed the first 20 lessons in c++, because I was buisy, but I will definitely remember you advise.Thanks man.

Also what exactly is the purpose of the "for(j=0;j<1;j++) " loop when all its doing is running it it only once? If that's the loop that is supposed to run th eprocess twicw try replacing "j<1" with "j=1" or "j<2"

i corected it to <=, later
Acunga
Member
Member
 
Posts: 71
Joined: Fri May 25, 2007 12:18 pm


Return to General Chat

Who is online

Users browsing this forum: No registered users and 0 guests