Aug 17, 2012 at 10:09am UTC
#include “stdio.h”
main();
{
float total, price == 2.99;
int number;
printf(“How many T-shirts would you like?”);
scanf(“n%f”, &number);
total = number * price;
printf(“That will cost you £total”, %f);
}
I'm very new to C++
Aug 17, 2012 at 10:23am UTC
I didn't write it, its to help me with homework, I need to find 6 things wrong with it
Aug 17, 2012 at 10:47am UTC
So what have you found so far??
Aug 17, 2012 at 10:48am UTC
Instead of
#include "stdio.h"
shall be
#include <cstdio>
instead of
main(); // error: presence of the semicolon is invalid
shall be
int main()
instead of
price == 2.99
shall be
price = 2.99
It looks like the string literal has different quotes
“How many T-shirts would you like?”
shall be
"How many T-shirts would you like?"
I think that literal n is not required in this string literal
scanf(“n %f”, &number);
shall be
scanf(“%f”, &number);
The same remark about literal quotes as above.
This statement will not be compiled
printf(“That will cost you £total”, %f);
shall be
printf(“That will cost you £%f”, total);
It is better to use namespace prefix before the functions as for example
std::printf, std::scanf because it is implementation-defined whether standard C names will be placed in the global namespace or not.
Also a return 0; statement could be placed in the body of main as the last statement though it is not obligatory.
Last edited on Aug 17, 2012 at 11:05am UTC
Aug 17, 2012 at 10:51am UTC
@vlad from moscow - why did you do that?
The OP is supposed to find the errors.
Aug 17, 2012 at 11:40am UTC
Just a question:
Is your code in c or c++?
Aug 17, 2012 at 2:47pm UTC
You should do your own homework. So you don't fail the class.