Welcome, Guest. Please login or register.

Author Topic: I need help with C(++)  (Read 4768 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline z5Topic starter

  • Sr. Member
  • ****
  • Join Date: May 2002
  • Posts: 366
    • Show all replies
    • http://ada.untergrund.net
I need help with C(++)
« on: April 03, 2003, 05:20:02 PM »
Hi!

i'm doing my exercises for my exam c(++). The compiler i use is Borland c++. I've run into this problem so i thought: why not ask on Amiga org ;-)

Here's the little program:
#include
#include
#include

void main(void)
  {
     const numberofstrings = 5;
     char str[numberofstrings][80],*p;
       
     for(p=str;p                {
                printf("Type string: ");
                gets(p);
                }
}

The problem is that my compiler doesn't allow p=str because str is a two dimensional array. I just wanted the pointer to point at the first string in my string array.

What i was trying to achieve is that the user gives a couple of strings and i store them in a string array (using pointers).

Thanks for any help
A.miga D.emoscene A.rchive: Relive the dreams...
 

Offline z5Topic starter

  • Sr. Member
  • ****
  • Join Date: May 2002
  • Posts: 366
    • Show all replies
    • http://ada.untergrund.net
Re: I need help with C(++)
« Reply #1 on: April 04, 2003, 11:59:33 AM »
my teacher will never believe that i coded this myself  :-D
A.miga D.emoscene A.rchive: Relive the dreams...
 

Offline z5Topic starter

  • Sr. Member
  • ****
  • Join Date: May 2002
  • Posts: 366
    • Show all replies
    • http://ada.untergrund.net
Re: I need help with C(++)
« Reply #2 on: April 05, 2003, 05:40:56 PM »
ok, i've got another problem:

#include
#include

void main(void)
{
int aantalmaaltijden, jarenklant, prijsmaaltijd, prijsmaxmaaltijd, korting;
int kortingonderdrie, kortingbovendrie;
float totalebedrag;
char klant[80];

printf("Geef de prijs van 1 maatijd: ");
scanf("%d",&prijsmaaltijd);
printf("Geef de prijs van 5 maaltijden: ");
scanf("%d",&prijsmaxmaaltijd);
printf("Geef de korting bij minder dan 3 jaar klant: ");
scanf("%d",&kortingonderdrie);
printf("Geef de korting als 3 of meer jaar klant: ");
scanf("%d",&kortingbovendrie);
printf("Geef de naam van de klant: ");
gets(klant);
printf("Geef het aantal maaltijden: ");
scanf("%d",&aantalmaaltijden);
printf("Geef aantal jaren klant: ");
scanf("%d",&jarenklant);
}

Don't mind all the text (it's dutch). The problem is the gets(klant). If i run the program, the program doesn't wait for something to be typed on the keyboard and jumps straight to the next printf.

Any ideas?
Thanks
A.miga D.emoscene A.rchive: Relive the dreams...
 

Offline z5Topic starter

  • Sr. Member
  • ****
  • Join Date: May 2002
  • Posts: 366
    • Show all replies
    • http://ada.untergrund.net
Re: I need help with C(++)
« Reply #3 on: April 05, 2003, 05:47:44 PM »
bingo  :-o

You're my hero Karlos  :-D

Seriously though, you seem to know a lot about programming, yet reading some threads i have the impression that you don't do it for a living? Why not?
A.miga D.emoscene A.rchive: Relive the dreams...
 

Offline z5Topic starter

  • Sr. Member
  • ****
  • Join Date: May 2002
  • Posts: 366
    • Show all replies
    • http://ada.untergrund.net
Re: I need help with C(++)
« Reply #4 on: April 14, 2003, 06:11:53 PM »
Can anybody explain the following problem (it's driving me nuts) in C:

When i do 0.20 / 0.20 and put the the result in a float, i get 1.00 (which is great  :-) )

When i do the same and put the result in an integer, i get 0 (:-x). So i'm doing int = float / float

Same goes for:
 0.20/0.10 results in 2 when i put it in a float
 0.20/0.10 results in 1 when i put the result in an integer??
A.miga D.emoscene A.rchive: Relive the dreams...
 

Offline z5Topic starter

  • Sr. Member
  • ****
  • Join Date: May 2002
  • Posts: 366
    • Show all replies
    • http://ada.untergrund.net
Re: I need help with C(++)
« Reply #5 on: April 14, 2003, 06:28:00 PM »
The cast doesn''t work.

Is there a function in c where i can drop everything behind the comma,
eg
float 5.20 => 5 but there must be no rounding up.?
A.miga D.emoscene A.rchive: Relive the dreams...