Does this program look right?

I need to write a program that prompts the user to input 3 values 2 integers and 1 float, and then display them. would what I have be correct?

Thanks!

WHAT ITS SUPPOSED TO LOOK LIKE:

Please enter article characteristics.
Article Number: 576
Number of pieces: 4
Price per piece: 12.9

Article Number Quantity Price per piece
576 4 12.90 dollars

MY ATTEMPT:

#include <stdio.h>

int main ()
{

int article number
char number of pieces
float price per piece

printf("Please enter article characteristics."\n);
scanf("%d:"\n, article number);
scanf("%s:"\n, number of pieces);
scanf("%f:"\n, price per piece);

printf("Article Number Quantity Price per piece"\n);



closed account (Eybjz8AR)
read up more is my suggestion

first off declaring your ints and floats are wrong it should be
int articleNumber{}; and not int article number
or int articleNumber = 0;

read up on syntax and also you can use cout << "hello world";
instead of print f. I would start with some tutorials because your missing quite a bit

also writing code you learn way more then being given the code
Last edited on
I'm going off of what we've learned in programming so far at school which is basically not much. thanks though

would the char and float parts be correct if I fixed it like you did for int?
Last edited on
Variable names cannot have white spaces. There are several ways to combine multiple words.
1
2
3
int thisisalongvariablename; // not easy to read, but works
char thisIsAnotherLongVariableName; 
float this_is_yet_another_long_variable_name; 

It does not matter what the variable type is.
ok thanks.

And we also are supposed to make a chart that calculates squares and cubes from 0-5 only using techniques we've learned so far but it seems like the only way to do that is to use stuff we havent learned yet. Any advice?
closed account (Eybjz8AR)
you could do something like

1
2
3
4
int x;
cout << "Enter a number you want squared \n";
cin >> x;
cout << x*x;


thats a very easy way to square a number a user enters. i dont know if your trying to make one program that does this though if so it wouldn't be super challenging there are ways of doing it in a simplistic manor. again this would work in visual studios. i dont know what compiler your using
cool thanks! and yea I'm using VS
Last edited on
Topic archived. No new replies allowed.