Jump to content

hey guys 

so i was trying to code a program that allowed me to add in a pattern 

the pattern is:

x+y=z

then it must add again but now x must be equal to z 

and y is just 1+1 until a maximum defined by the user 

the first x must also be defined by the user

0+1=1

1+2=3

3+3=6

6+4=10

10+5=15

it must do all this calculations in background and only print to the screen the result of all the calculation until the number defined as maximum in y

 

hope you guys can help

thx

Fx-8150 @ 4.7Ghz/Corsair h110/asus hd7770 1gb/Gigabyte 990fxa ud3/corsair xms3 4Gb 1333Mhz 8-8-8-20/WD scorpio black 250GB/hp w19ev/nox nx520/logitech access keyboard (y-sr34)/1life gm:lightning/

Link to comment
https://linustechtips.com/topic/598931-having-some-fun-in-c/
Share on other sites

Link to post
Share on other sites

1 minute ago, Moonzy said:

not sure if school work `-`

 


(get input from user for x and maximum)

y = 1;

while(x < maximum){

x+y=z;
x=z;
y++;

(insert code to display x or z here)
}

 

nope not school work just bored and want to make a calculator for savings :P

Fx-8150 @ 4.7Ghz/Corsair h110/asus hd7770 1gb/Gigabyte 990fxa ud3/corsair xms3 4Gb 1333Mhz 8-8-8-20/WD scorpio black 250GB/hp w19ev/nox nx520/logitech access keyboard (y-sr34)/1life gm:lightning/

Link to comment
https://linustechtips.com/topic/598931-having-some-fun-in-c/#findComment-7775735
Share on other sites

Link to post
Share on other sites

2 minutes ago, pm94 said:

nope not school work just bored and want to make a calculator for savings :P

i think there's something wrong

 

while (x < maximum), the x should be changed to y

i think i misunderstood it lol

-sigh- feeling like I'm being too negative lately

Link to comment
https://linustechtips.com/topic/598931-having-some-fun-in-c/#findComment-7775743
Share on other sites

Link to post
Share on other sites

8 minutes ago, Moonzy said:

i think there's something wrong

 

while (x < maximum), the x should be changed to y

i think i misunderstood it lol

i'm getting this error

 

error: lvalue required as left operand of assignment                                                                                                                        
 x+y=z;

here is the code so far

 

#include <stdio.h>
 
int main()
{
    int maximum;
    int y;
    int x;
    int z;
 
   printf("numero de semanas\n");
   scanf("%d", &x);
   printf("saldo\n");
   scanf("%d",&maximum);
y = 1;
while(y < maximum){

x+y=z;
x=z;
y++;

printf("%d\n",z);

}
   return 0;

}

Fx-8150 @ 4.7Ghz/Corsair h110/asus hd7770 1gb/Gigabyte 990fxa ud3/corsair xms3 4Gb 1333Mhz 8-8-8-20/WD scorpio black 250GB/hp w19ev/nox nx520/logitech access keyboard (y-sr34)/1life gm:lightning/

Link to comment
https://linustechtips.com/topic/598931-having-some-fun-in-c/#findComment-7775771
Share on other sites

Link to post
Share on other sites

1 minute ago, pm94 said:

i'm getting this error

 

error: lvalue required as left operand of assignment                                                                                                                        
 x+y=z;

here is the code so far

 

#include <stdio.h>
 
int main()
{
    int maximum;
    int y;
    int x;
    int z;
 
   printf("numero de semanas\n");
   scanf("%d", &x);
   printf("saldo\n");
   scanf("%d",&maximum);
y = 1;
while(y < maximum){

x+y=z;
x=z;
y++;

printf("%d\n",z);

}
   return 0;

try changing

int x; -> int x = 0;

 

as x doesnt have a value when you compile, the compiler spits this error

-sigh- feeling like I'm being too negative lately

Link to comment
https://linustechtips.com/topic/598931-having-some-fun-in-c/#findComment-7775781
Share on other sites

Link to post
Share on other sites

1 minute ago, Moonzy said:

try changing

int x; -> int x = 0;

 

as x doesnt have a value when you compile, the compiler spits this error

still getting the same error

Fx-8150 @ 4.7Ghz/Corsair h110/asus hd7770 1gb/Gigabyte 990fxa ud3/corsair xms3 4Gb 1333Mhz 8-8-8-20/WD scorpio black 250GB/hp w19ev/nox nx520/logitech access keyboard (y-sr34)/1life gm:lightning/

Link to comment
https://linustechtips.com/topic/598931-having-some-fun-in-c/#findComment-7775787
Share on other sites

Link to post
Share on other sites

6 minutes ago, Moonzy said:

try z = x + y; instead

well it worked but when i tried 

i gave it a maximum of 1 it started spitting out a bunch of numbers 

didn't even ask the second parameter

btw i wrote the code wrong last time 

fixed it now

 

#include <stdio.h>
 
int main()
{
    int maximum;
    int y;
    int x = 0;
    int z;
 
   printf("numero de semanas\n");
   scanf("%d", &maximum);
   printf("saldo\n");
   scanf("%d",&x);
y = 1;
while(y < maximum){

z=x+y;
x=z;
y++;

printf("%d\n",z);

}
   return 0;
}

 

Fx-8150 @ 4.7Ghz/Corsair h110/asus hd7770 1gb/Gigabyte 990fxa ud3/corsair xms3 4Gb 1333Mhz 8-8-8-20/WD scorpio black 250GB/hp w19ev/nox nx520/logitech access keyboard (y-sr34)/1life gm:lightning/

Link to comment
https://linustechtips.com/topic/598931-having-some-fun-in-c/#findComment-7775803
Share on other sites

Link to post
Share on other sites

2 minutes ago, pm94 said:

well it worked but when i tried 

i gave it a maximum of 1 it started spitting out a bunch of numbers 

didn't even ask the second parameter

well... im not familiar with C so... im familiar with c++ lol

but if you're using the scanf properly then it shouldnt happen (i know printf, not scan f)

-sigh- feeling like I'm being too negative lately

Link to comment
https://linustechtips.com/topic/598931-having-some-fun-in-c/#findComment-7775827
Share on other sites

Link to post
Share on other sites

5 minutes ago, Moonzy said:

well... im not familiar with C so... im familiar with c++ lol

but if you're using the scanf properly then it shouldnt happen (i know printf, not scan f)

hahaha i learned C in school like 3years ago so most of it i have forgotten 

if im not mistaken scanf as i used it should work but i will search online

thanks very much for your help

Fx-8150 @ 4.7Ghz/Corsair h110/asus hd7770 1gb/Gigabyte 990fxa ud3/corsair xms3 4Gb 1333Mhz 8-8-8-20/WD scorpio black 250GB/hp w19ev/nox nx520/logitech access keyboard (y-sr34)/1life gm:lightning/

Link to comment
https://linustechtips.com/topic/598931-having-some-fun-in-c/#findComment-7775849
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×